Can anyone explain the difference between $scope and $rootScope?
I think
We can get ng-model properties in particular cont
The main difference is the availability of the property assigned with the object. A property assigned with $scope
cannot be used outside the controller in which it is defined whereas a property assigned with $rootScope
can be used anywhere.
Example: If in the example below you replace $rootScope
with $scope
the department property will not be populated from the first controller in the second one
angular.module('example', [])
.controller('GreetController', ['$scope', '$rootScope',
function($scope, $rootScope) {
$scope.name = 'World';
$rootScope.department = 'Angular';
}
])
.controller('ListController', ['$scope',
function($scope) {
$scope.names = ['Igor', 'Misko', 'Vojta'];
}
]);
Hello {{name}}!
- {{name}} from {{department}}