【发布时间】:2018-11-03 17:08:03
【问题描述】:
我对 AngularJS 1.4 (TypeScript) 有一个非常奇怪的问题。问题出在控制器中,我有一个变量,可以在输入文本框中查看该值。 但是,当我编辑此文本框中的值并单击按钮时,此变量的值不会改变(!)。
HTML 视图
<div class="form-group">
<label>Title</label>
<input class="form-control" ng-model="serviceTitle">
</div>
<div class="form-group">
<button class="btn btn-primary" ng-click="updateServiceIdentification()">Update Service Identifcation</button>
</div>
控制器:
$scope.serviceTitle = "Test";
$scope.updateServiceIdentification = ()=> {
// after changing value in view, the value here is still "Test"????
alert($scope.serviceTitle);
}
如果我在 HTML 视图中添加测试标签
<h1>{{serviceTitle}}</h1>
当我更改输入文本框的值时,新的值可以打印在这个标签中。
【问题讨论】:
-
尝试不使用
$scope。 -
@KaustubhKhare 你是什么意思????
-
喜欢这个
alert(serviceTitle);或alert(this.serviceTitle); -
[ts] 对于这两种情况,“AdminOWSMetadataManagementController”类型都不存在属性“serviceTitle”。
标签: angularjs typescript angularjs-directive angularjs-scope