简体   繁体   中英

Best way to inject a module.factory into another module in angular.js

I'm creating my first module and i don't know how to inject a simple object factory.

angular.module('mymodule', [])
.factory('mymodulefactory', function () {
    return { a:1, b:2 };
});

This is my app:

angular.module('myapp', ['mymodule'])
.controller('myController', function($scope, mymodule){ //error
    console.log(mymodule) //undefined
    console.log(mymodulefactory) //undefined
});

You can inject like this:

.controller('myController', function($scope, mymodulefactory) {
    ...
});

http://jsfiddle.net/rm5kc4u1/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM