I have controller is named "UserController"
in top of page:
<div ng-controller="UserController"><input type="text" ng-model="search"></div>
Also the same controller in bottom page from directive ng-view
:
<div class="bottom" ng-controller="UserController">{{search}}</div>
Why I dont get value {{search}}
in bottom part, when I fill field input in top?
Can I use one controller two times in a page?
Yes, you can use two controllers in AngularJs, Here is a demo.
What happens when I use ng-controller?
When you add ng-controller to a DOM element, angular create an instance of controller function and attaches it with that DOM, and thats why there is no two way data-binding between those divs.
How can I use data binding to share data between controllers?
You can use $rootScope
variable or you can use services.
you can create service and inject in controller as dependency, so you can access its property with two way binding feature.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments