javascript - Multiple controllers with AngularJS in single page app -
i want know how utilize multiple controllers single page application. have tried figure out , i've found questions similar mine, there ton of different answers solving specific problem end not using multiple controllers single page app.
is because not wise utilize multiple controllers single page? or not possible?
let's have kick-ass image carousel controller working main page, larn how (let's say) utilize modals , need new controller (or other thing need controller). then?
i have seen answers other questions inquire same things me , people reply "*omg. why that, this...".
what best way, or how do it?
edit
many of answering declare 2 controllers , utilize ng-controller phone call it. utilize bit of code below , phone call mainctrl ng-controller.
app.config(function($routeprovider, $locationprovider) { $routeprovider .when('/', { templateurl: "templates/main.html", controller:'mainctrl', }) .otherwise({ template: 'does not exists' }); }); why need set controller here if can utilize ng-controller without it? confused me. (and can't add together 2 controllers way, think...)
what problem? utilize multiple controllers, utilize multiple ngcontroller directives:
<div class="widget" ng-controller="widgetcontroller"> <p>stuff here</p> </div> <div class="menu" ng-controller="menucontroller"> <p>other stuff here</p> </div> you need have controllers available in application module, usual.
the basic way simple declaring controller functions this:
function widgetcontroller($scope) { // stuff here } function menucontroller($scope) { // stuff here } javascript angularjs controller
No comments:
Post a Comment