因为ng-include指令会创建新的作用域,导致父页面无法找到ng-model绑定的值。
解决方法:在被ng-include的界面加上$parent,这样父类就能获取到值了
<div ng-include="'s1.html'"></div>
<!-- s1.html -->
<input ng-model="$parent.value" type="text">
var app = angular.module('app', []);
app.controller('c', function($scope) {
$scope.$watch("value", function(newVal, oldVal){
console.log("newVal:", newVal);
})
});