Sunday, September 3, 2017

Constant in AngularJS

  • A constant can be injected anywhere.
  • A constant cannot be intercepted by a decorator that means that the value of a constant should never be changed.
Example:
JS:
       MyApp.constant('ProjectVersion', "1.0.0.0");
       MyApp.constant('ProjectTitle', "Demo");
       MyApp.config(function (ProjectVersion) {
                     var ProjectVersionNew = ProjectVersion ;
          });
       MyApp.controller('constantController', function ($scope,ProjectVersion,ProjectTitle) {
                 $scope.Version=ProjectVersion;
                $scope.title=ProjectTitle;
       });
HTML:
     <div ng-controller="constantController">
              Project Title: {{title}}<br/>
              Project Version: {{Version}}
      </div>

No comments:

Post a Comment