mercredi 11 février 2015

How to inject a unique module for each controller in angularjs


In the same way as $scope is independent of each controller. Exists the way to create a module independent for each controller?



angular.module('mymodule', []).service('mymodule', function () {});

angular.module('myapp', ['mymodule'])

.controller('myController2', function($scope, mymodule) {

console.log(
$scope.hello, // undefined
mymodule.hello, // "world"
s === $scope, // false
m === mymodule // true
);

})

.controller('myController', function($scope, mymodule) {

s = $scope;
m = mymodule;
$scope.hello = "world";
mymodule.hello = "world";

});


http://ift.tt/16ZM15j


I tried with factory's and providers.





Aucun commentaire:

Enregistrer un commentaire