I am using angularjs 1.4, and in one of my angular controller I have to use jQuery. but when I am trying to pass it as dependency, it is not working.
I tried below code, but no success
(function () {
'use strict';
var app= angular.module('app');
app.controller('getUserInfo', ['jQuery',
function($) {
// some logic
}]);
})();
I also tried below code, but no success
(function () {
'use strict';
var app= angular.module('app');
app.controller('getUserInfo', ['$',
function($) {
// some logic
}]);
})();
Can some please guide what I am doing wrong.
If you load jQuery.js before angular.js, AngularJS will make it available as
angular.element
and add Angular specific methods as well.From the Docs:
For more information see the AngularJS angular.element API Reference.
You could create your own constant inside your app module & then you can inject that dependency where ever you want.
I chosen constant, because It would be available to inject its dependency inside config phase of angular.
But as you wanted to inject dependency of jQuery inside a controller, I'd say NO. Don't do that. Basically you shouldn't do any DOM manipulation from the controller. You can do that from the directive, which has capability to playing in better way with DOM.