在角JS单页多个应用程序 [英] multiple apps in single page in angular js
本文介绍了在角JS单页多个应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在栋JS角的应用程序。
I am buliding an application in angular js.
我有两个控制器的两个视图。
I have two controllers for two views.
JavaScript的:
javascript:
var myApp1 = angular.module('myApp1', []);
myApp1.controller('myController1', function($scope) {
alert("check");
$scope.x = 'test';
});
var myApp2 = angular.module('myApp2', []);
myApp2.controller('myController2', function($scope) {
alert("check1");
$scope.x = 'test';
});
HTML
<div ng-app="myApp1">
<div ng-controller="myController1">
<input type="text" ng-model="x" /> {{x}}
</div>
</div>
<div ng-app="myApp2">
<div ng-controller="myController2">
<input type="text" ng-model="x" /> {{x}}
</div>
</div>
只有第一个控制器得到执行。
only the first controller is getting executed.
请指教
推荐答案
您需要引导每个应用程序如下:
You need to bootstrap each app as follows:
var myApp1 = angular.module('myApp1', []);
myApp1.controller('myController1', function($scope) {
alert("check");
$scope.x = 'test';
});
angular.bootstrap(document.getElementById('myApp1Div'),['myApp1']);
var myApp2 = angular.module('myApp2', []);
myApp2.controller('myController2', function($scope) {
alert("check1");
$scope.x = 'test';
});
angular.bootstrap(document.getElementById('myApp2Div'),['myApp2']);
和HTML
<div id="myApp1Div" >
<div ng-controller="myController1">
<input type="text" ng-model="x" /> {{x}}
</div>
</div>
<div id="myApp2Div" >
<div ng-controller="myController2">
<input type="text" ng-model="x" /> {{x}}
</div>
</div>
这篇关于在角JS单页多个应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文