constants in AngularJs

Constants in AngularJs

Hello everyone, I am going to share the code sample for "how to create the constants in AngularJs?" and "how to inject in angular controller?". The defined constants are ready to use by angular controller as give below.

 * @angular root module.
var app = angular.module('myConstantApp');

 * @The constants defined in myServiceConst are ready for use by controller.
           { blankMsg: "Please enter your service’s number." ,
             numLessGraterThen10 :'put msg'});

  * Controller using constants.
  * @ng-Inject : my  myServiceConst  is going to inject by the linkToMyServices contoller.
app.controller('linkToMyServices', function ($scope, myServiceConst) {
     * @Initialize the default variable.
    $scope.isError = false;

       * @name Check Service
       * @desc This scope is used to validate the services for link to new service.
       * @param {mobile no / service no}
       * @returns {validate msg}
    $scope.CheckService = function (mobile) {
        $scope.isError = true;

        //If services number is blank then
        if (mobile == null) {
            $scope.lblMessages = myServiceConst.blankMsg;
The HTML code
<div class="confirmServiceFirst">
    <input ng-model="txtCheckServiceNo" type="text">
    <a ng-click="CheckService(txtCheckServiceNo)">Check service</a>
    <a ng-show="lnkChangeService">Change service</a>
    <label ng-model="lblMessages" ng-show="isError">{{lblMessages}}</label>

The output look like below images.


Hey! I'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
My Blogs - and
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like
Post a Comment Powered by Blogger.
ASK Questions