javascript - Why does adding a parameter to DDO factory function break the app? -
i under impression (correctly, googling shows) javascript functions can take amount of parameters, regardless of what's intended.
so it's unusual directive works on here
... module.directive('aye', function(){ homecoming { restrict: 'ae', replace: 'true', template: "<p> hi </p>" }; }); </script> </head> <body ng-controller="mycontroller"> <div> {{ airportsarray() }} </div> <div aye></div> </body> </html>
but not on here
module.directive('aye', function(injectables){ homecoming { restrict: 'ae', replace: 'true', template: "<p> hi </p>" }; }); </script> </head> <body ng-controller="mycontroller"> <div> {{ airportsarray() }} </div> <div aye></div> </body> </html>
i removing parameter (which found in angular's own documentation) injectables
. why give me errors like
error: [$injector:unpr] http://errors.angularjs.org/1.2.15/$injector/unpr?p0=injectablesprovider%20%3c-%20injectables%20%3c-%20ayedirective
can explain?
angular passes in these values via dependency injection. , determines inject based upon name of parameter (it can more complicated when minifying). , in illustration above have not identified component (service/factory/value/etc) name "injectables" error showing can not find "injectables"
//create can injected: module.service('fooservice', function($http){ /* ... functions here ... */ }); //inject defined piece directive: module.directive('mydirective', function(fooservice){ });
when angular needs create instance of "mydirective" see needs parameter "fooservice" go dependency resolver find pass in directive paramter.
javascript angularjs parameters
No comments:
Post a Comment