Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • $scope in Angularjs

    • 0
    • 1
    • 1
    • 1
    • 0
    • 0
    • 0
    • 0
    • 216
    Comment on it

    Hi All,

    Today we will discuss about "$scope in Angularjs".

    First of all what is $scope ?

    A $scope is an object instance of a controller. When ng-controller directive is encountered at that time $scope gets created.

    For example:
    In the below code we have two controllers firstController and secondController. In both the controllers we have a ControllerName variable.

    function firstController($scope)
    {
    $scope.ControllerName = firstController";        
    }
    function secondController($scope)
    {
    $scope.ControllerName = secondController;
    }
    



    We can attach the both controllers to HTML UI where we are using ng-controller directive.

    For example:
    You can see in the below code where ng-controller directive attaches firstController with firstDiv tag and secondController with secondDiv tag.

    <div id=firstDiv"; ng-controller=firstController>
         {{ControllerName}} created 
    </div>
    <div id=secondDiv"; ng-controller=secondController">
        {{ControllerName}} created 
    </div>
    


    Now the internal functionality is, when HTML DOM is created the Angular parser starts running on the DOM.
    Parser first finds ng-controller directive then both controller one by one(firstContorller and secondController) and creates a news instance of $scope object and connects to respective div i.e firstDiv, secondDiv.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: