python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
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.
 */
app.constant('myServiceConst',
           { 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) {
            alert(myServiceConst.blankMsg);
            $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>
</div>

The output look like below images.



ANIL SINGH

Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - http://code-sample.com and http://code-sample.xyz
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like
www.code-sample.com/. Powered by Blogger.
ASK Questions