javascript - Why does adding a parameter to DDO factory function break the app? -


I was under the impression (in the right way, my Googling shows) that Javascript functions can take parameters in any quantity .

So it is weird that my instruction works here

  ... module directive ('A', function) (return {restricted: 'AE', replaced) Do: 'right', template: "

High "};}); & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body ng-controller = "myController" & gt; & Lt; Div & gt; {{Airport Ore ()}} & lt; / Div & gt; & Lt; Div aye & gt; & Lt; / Div & gt; & Lt; / Body & gt; & Lt; / Html & gt;

but not here

  module.directive ('aye', function (injectables) {return {restricted: 'AE', replace: ' True ', template: "& lt; p & gt; hi "};}); & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body ng-controller = "myController" & gt; & Lt; Div & gt; {{Airport Ore ()}} & lt; / Div & gt; & Lt; Div aye & gt; & Lt; / Div & gt; & Lt; / Body & gt; & Lt; / Html & gt;  

I'm just removing the parameters (which I found) injectables why does this error me

  error: [$ Injector: unpr] http://errors.angularjs.org/1.2.15/$injector/unpr?p0=injectablesProvider%20%3C-%20injectables%20%3C-%20yDirective  
< P> Can anyone explain?

Angular passes in these values ​​through dependency injection. And it determines what to inject based on the name of the parameter (when you have to reduce it, it can be more complex). And in the above example, you have not identified any component (service / factory / value / etc) under the name "enzibles", so the error that is showing you is that it can not get "injection"

  // Create something that can be injected: module.service ('fooService', function ($ http) {/ * ... some functions here ... *}); // This defined piece injection in your instruction: module.directive ('myDirective', function (fooService) {}); When coal needs to be made an example of "My Directive", then it will see that the parameter "fooService" is required, so that it can be found in its dependency resolver. Go and direct it as your parameter. 


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -