In AngularJs, we are using global constant and value. Both are working same but only difference in constant and value as give below.
• The constants value can't change anywhere in across application that means the value of constants can't inject.
• But the value can be change anywhere in across application as per your requirements that means the value of constants can be inject anywhere in application.
In the below example,
I am going to share the how to Inject the value objects and use of value objects. Please see the detail as given below.
• The constants value can't change anywhere in across application that means the value of constants can't inject.
• But the value can be change anywhere in across application as per your requirements that means the value of constants can be inject anywhere in application.
In the below example,
I am going to share the how to Inject the value objects and use of value objects. Please see the detail as given below.
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Injected to Angular constant, value</title> <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.6/angular.min.js"></script> <script> var app = angular.module('ConstApp', []); //CREATE A VALUE OBJECT AS "VALUE" AND PASS TO CONTROLLER. app.value("value", 'Anil Singh'); app.controller('constCtrl', ["$scope", "value", function ($scope, value) { $scope.name = value; }]); </script> </head> <body ng-app="ConstApp" ng-controller="constCtrl"> <h1>Injected to Angular Value</h1> <p>Result: {{name}}</p> </body> </html>
Blogger Comment
Facebook Comment