in 1 of many angularjs style guides, suggests setting controller this
function myctrl(dependency1, dependency2){ } module.controller('myctrl', myctrl); i tried doing following, in use $watch on $scope. however, error $watch not function, i'm assuming i'm not injecting scope properly.
this code in app/controllers/myctrl.js file
function myctrl($scope, mystorage){ var mystore = $scope.mystore = mystorage.get(); $scope.$watch('mystore', function(){ //code ommitted } } angular.module('myapp').controller('myctrl', myctrl); question, how inject $scope , other dependencies using style?
previously, did way , worked fine.
angular.module('myapp').controller('myctrl', ['$scope', 'mystorage', function mycontroller($scope, mystorage){ } ]);
myctrl.$inject = ['dependency1', 'dependency2']; function myctrl(dependency1, dependency2){ } yes, can come before function (just annotation in java).
Comments
Post a Comment