Constants in AngularJs



Constants can be injected everywhere including configuration calls. So when you call module.config and set up states,colors,months,weeks or other run time settings you can inject constant values.

<!DOCTYPEhtml>
<html ng-app="app">
<head>
    <title></title>
<metacharset="utf-8"/>
<script src="Scripts/angular.min.js"></script>
</head>
<body ng-controller ="MyController">
    {{title}}
 
    <script>
        var app = angular.module('app', []);
        // Storing a single constant value
        app.constant('MOVIE_SAMPLE''The Movie');
        // Now we inject our constant value into a My controller
        app.controller('MyController'function ($scope, MOVIE_SAMPLE){
$scope.title=MOVIE_SAMPLE;
});
</script>
 
</body>
</html>

Constants in angularJs
Constants in AngularJs
 



Comments

  1. This comment has been removed by a blog administrator.

    ReplyDelete

Post a Comment