AngularJS Tutorial 20 - Controller As Syntax

Pubblicato il: 11 febbraio 2017
sul canale di: Nisha Singla
853
17

In this video we have discussed about Controller As syntax in angular JS

In my previous video we have learnt about nested controller in that child controller will inherit the data from its parent scope.
When you bind the property on $scope in nested controller you will unexpected output

So everytime when you access property inside parent scope you have to access the property using $parent property in angularjs.

But this lead to again lot of confusion because with each level deep you need to add $parent for immediate parent. so in this case it is very difficult to remember the scope of controller

So to get rid from this issue you can create an alias of your controller so that wherever you want to access parent scope , all you need to use mention the alias name that will act like a object
So first rule to create Controller-As Syntax is you need to bind the properties of controller on this rather then $scope object.

app.controller("ParentController",function(){
this.username ='John'
});

Now when you use ng-controller directive inside index.html you need to create alias as well using "AS" keyword

parentController as parent

Visit complete playlist on angular js @    • AngularJS Tutorial 1  -  Introduction  

Visit my facebook page@

  / angularjs4beginners  


In questa pagina del sito puoi guardare il video online AngularJS Tutorial 20 - Controller As Syntax della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Nisha Singla 11 febbraio 2017, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 853 volte e gli è piaciuto 17 spettatori. Buona visione!