AnjularJS controllers :
As per SOLID principal as well MVC suggested
way is separation of conterns(Model,View,Controller) we have to prepare object/model
is job of controller, we can construct/prepare model itself at controller but
it is violation mvc pattern.
Model(employee)---------$scope-------View
Scripts.js------------------anjularjs------demo.html
|
Constructing a
complex object/employee in controller and attaching to $scope object. $scope is
a glue between model object and view.
Notes :
1. In anjularjs if we missspelled the controller name then anjularjs will report the error.
as like
Browser : Developer tolls--console
Error : Argument "mycontroller1" is not a function, got undefined.
to get good understandable error description use anjular.js.(not minified version of anjular.js)
2. missspelled the property of object like
{{ employee.gende} instead of {{ employee.gender}}----anjular not report any error.
simply it will ignore the gender value.
The differences are that, first, in the ng-controller directive we not only pass the name of the registered controller, but also, a variable name for an instance of the controller; vm stands for ViewModel but a more meaningful name can be used and we’ll talk about it later. Second, when we use double curly braces or the ng-model directive, we use vm.myModel to access to the variable defined in the controller. Read more: AngularJS Training and Tutorial
ReplyDelete