In AngularJS, value is a simple object. It can be
a number, string or JavaScript object. It is used to pass values in factories,
services or controllers during run and config phase. Value cannot
be injected into configurations, but it can be intercepted by decorator
means that the value can be changed.
Example:
JS
          // Declare a default for value
MyApp.value('greeting', 'Hello');
// Declare a update value by using decorator
MyApp.config(function ($provide) {
$provide.decorator('greeting', function ($delegate) {
return $delegate + ' World!';
});
});
// bind value in view
MyApp.controller("ValueController", function($scope, greeting) {
$scope.greeting=greeting;
});
HTML
<div ng-controller="ValueController">
<span> bind value in view :</span> {{greeting}}
</div>
MyApp.value('greeting', 'Hello');
// Declare a update value by using decorator
MyApp.config(function ($provide) {
$provide.decorator('greeting', function ($delegate) {
return $delegate + ' World!';
});
});
// bind value in view
MyApp.controller("ValueController", function($scope, greeting) {
$scope.greeting=greeting;
});
HTML
<div ng-controller="ValueController">
<span> bind value in view :</span> {{greeting}}
</div>
 
No comments:
Post a Comment