Why does not work two controller in Angular JS?

Kaffarov

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?

Laxmikant Dange

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.

edited at
0

Comments

0 comments
Login to comment

Related

Why does an Angular controller that is a function work, but a controller in a package does not?

Why Angular js Service does not work?

why my angular js code does not work

Why this simple Angular.js example does not work?

if two collectionviews in one controller sizeForItemAtIndexPath does not work

Why does a string method not work in home controller?

Phonegap : Angular Controller does not work in new window

Why ng-controller and ng-repeat doesn't work together inside same tag in Angular JS?

Does not work route in Angular JS?

Angular js binding does not work

Why does Angular Controller need "$scope"

Why does this two's complement shortcut work?

Why constructor of two root service does not work?

Why does not filter Angular JS?

Why addClass does not work for DOM element in Angular?

why selection does not work as it should? angular material

Why does my navbar component not work in Angular?

Angular.js: How does $eval work and why is it different from vanilla eval?

Angular js with MVC: locationProvider.html5Mode(true) Links Does Not Work, becuse it want to get controller and action from Server

Why my ajax/fetch call does not work with no Route in my controller?

In ruby on rails, why some controller does not work in the production environment?

Why does Unity (DI) work in the Controller, but not in my service layer?

Why useLocalStorage does not work with Next.js?

Why does sorting a JS array of numbers with < work?

JS - Why does await not work in class

Why does vanilla js addEventListener not work in WordPress?

Why does the Foursquare API JS not work with HTTPS?

Why does JS desctructuring assignment work with numbers

why splice not work properly in angular js