Search code examples
angularjsasp.net-mvcangularjs-injectorangular-route-segment

I can't use third party js with angular js and ASP.NET MVC


Hello I am creating application with ASP.NET MVC and Angular js.

Everything is running fine but when I want to use any third party js for angular js it is not allowing to do ...

I have created three js files.

1) app.js

var app;
(function () {
    app = angular.module("ANG", []);

    app.factory('GlobalService', function () {
        return {
            urlBase: 'myserviceurl/',
            UserName: '',
            UserRole: ''
        };
    });
})();

2) Controller.js

   app.controller("CustomerCtrl", ["$scope", "$q", "VendorService", "CustomerService", "$filter", function ($scope, $q, vendorService, customerService, $filter){
       //My code here
}
]);

3) Service.js

app.service('VendorService', ["$http", "$q", "GlobalService", function ($http, $q, globalService) {
//My service calling
}]);

4) Implemented in View

<html lang="en" id="htmlMainPage" ng-app="ANG">

I want to use multiselection js to implement multiselection dropdownlist.

I have done below one line change only and in controller and view further changes.

app.js

app = angular.module("ANG", ["angularjs-dropdown-multiselect"]);

It's running fine as well but other pages who has also use this app.js giving me an error.

enter image description here


Solution

  • Just look into the reference of the js you have given.

    You have to give reference or add multiselect.js in the layout page because as you have told in the question how you implemented the app.js.

    <html lang="en" id="htmlMainPage" ng-app="ANG">
    

    It will call every time when any view load and find for the multiselect.js reference and gives you the injector error and will not go further.

    Refer: Angular injector error