【发布时间】:2015-12-22 21:20:59
【问题描述】:
我是 angularjs 的初学者,目前我正面临 ng-include 的问题。
我有一个使用部分的测试应用程序。 这是我的代码。
<html ng-app ="TextboxExample">
<head>
<title>Settings</title>
<script src="angular.js"></script>
</head>
<body ng-controller="ExampleController">
<div ng-include src = "'view.html'"></div>
<script>
angular.module('TextboxExample', [])
.controller('ExampleController', ['$scope', function($scope) {
$scope.textboxVal = 'fddfd';
$scope.ReadGeneralSettings = function() {
alert($scope.textboxVal);
}
$scope.ResetGeneralSettings = function() {
$scope.textboxVal = 'fddfd';
}
}]);
</script>
<button class="pull-right" ng-click = "ReadGeneralSettings()">Read</button>
<button class="pull-right" ng-click = "ResetGeneralSettings()">Cancel</button>
</body>
</html>
部分代码view.html是
<input type="text" ng-model="textboxVal">
由于某种原因,当我在文本框中输入值时,设置为 ng-model 的 textboxVal 不会得到更新。 但是如果我不使用 ng-include 并直接将 view.html 的内容添加到主 html 文件中,这会很好。 请帮忙。
谢谢 苏尼尔
【问题讨论】:
-
ng-include 创建一个新范围
-
好的,我可以让它工作吗?
-
在下面查看我的答案
标签: javascript angularjs angularjs-ng-include