我正在通过AngularJS构建单页应用程序我的所有控制器一个接一个地工作得很好但是当我将它们并排放在标签内时,问题就出现了。
首先是我的标签
<div class="tab-content">
<div id="plan" ng-include="'plan.html'" ng-controller="dailyController" class="tab-pane fade in active"></div>
<div id="program" ng-include="'program.html'" ng-controller="programController" class="tab-pane fade"></div>
<div id="secreter" ng-include="'secreter.html'" ng-controller="secreterController" class="tab-pane fade"></div>
<div id="responsibility" ng-include="'responsibility_lists.html'" ng-controller="responsiblityCtrl" class="tab-pane fade"></div>
<div id="appointment" ng-include="'appointment.html'" ng-controller="appointmentCtrl" class="tab-pane fade"></div>
<div id="dayoff" ng-include="'dayoff.html'" ng-controller="dayOffCtrl" class="tab-pane fade"></div>
<div id="message" ng-include="'message.html'" ng-controller="messageCtrl" class="tab-pane fade"></div>
<div id="pre_record_admin" ng-include src="'pre_record_admin.html'" class="tab-pane fade"></div>
<div id="settings" ng-include="'settings.html'" ng-controller="settingsController" class="tab-pane fade"></div>
</div>
我的问题出在&#39; program&#39;并且&#39; secreter&#39;标签他们的控制器有很多相同的命名函数和变量。
这两个页面包含两个日期输入,并根据此日期输入的值生成一个表格,但是当我从program.html页面更改日期输入时,它会触发secreter.html页面中的表格,反之亦然。 #39;弄清楚原因。
这是program.html
的输入<input class="form-control pull-left" style="width:90%" type="date" ng-model="selectedDate" ng-change="dateChangeProgram(selectedDate);">
这是secreter.html的输入
<input class="form-control pull-left" style="width:85%" type="date" ng-model="selectedDate" ng-change="dateChange(selectedDate);">
我将programController的声明更改为程序
ng-controller="programController as program"
并用&#39;这个&#39;改变了变量和函数的声明。而不是&#39; $ scope&#39;当然还有我的HTML
<input class="form-control pull-left" style="width:90%" type="date" ng-model="program.selectedDate" ng-change="program.dateChangeProgram(program.selectedDate);"></input>
但这并没有帮助。
programController声明
.controller('programController', function($scope,$q,$window,$log,$http,$filter,$parse,$document) {
var vm = this;
vm.days=[];
vm.students=[];
//Functions and variables...
secreterController声明
.controller('secreterController', function($scope,$q,$window,$log,$http,$filter,$parse,$document) {
$scope.days=[];
$scope.students=[];
//Functions and variables...