As a newcomer to Angular, I have been using it for the past two months and now faced with the task of migrating from AngularJS to Angular in my project. The previous developer heavily relied on $rootScopes to store values across controllers, but I am opting to use services instead for a smoother transition to Angular.
I would appreciate it if you could review my code and point out any mistakes: plnkr code
Below is the snippet where I created a factory service and attempted to access it in other controllers. app.js
angular.module('myApp', [])
.factory('Data', function(){
return {message: "I'm a data from a Service"}
});
first.js
angular.module('myApp', [])
.controller(FirstCtrl, function($scope, $rootScope){
$scope.data = Data;
});
second.js
angular.module('myApp', [])
.controller(SecondCtrl, function($scope){
$scope.data = Data;
});