angularjs - can controllers create arbitrary properties in the $rootScope in Angular -
is legal controller in angular?
$rootscope.somearbitaryobject = ["fee", "fie", "fo", "fum]; or
$rootscope.foo = {name: "jane q. public", favoritecolor: "green"}
yes, legal if want controllers have access model.
a better practice use services can inject 1 or more controllers:
var myapp = angular.module('myapp', []); myapp.factory('myservice', function () { return { message: "i'm data service" }; }); myapp.controller('firstctrl', function($scope, myservice) { $scope.data = myservice; }); myapp.controller('secondctrl', function($scope, myservice) { $scope.data = myservice; }); any change make myservice properties in 1 controller affect other controllers use myservice.
Comments
Post a Comment