在 Angular UI 提前输入中未刷新模型
Model is not refreshed in Angular UI type-ahead
要复制问题 in this plunk,请在字段中输入任何内容,select 任意行,然后单击按钮 "Change Name"。您会看到模型已更改,但 Angular 提前输入字段不反映模型。有什么想法吗?
HTML
<input type="text" ng-model="ds"
uib-typeahead="ds as ds.name for ds in queryList($viewValue)" >
<p>Model: {{ds}}</p>
<button ng-click="changeName()">Change Name</button>
Javascript
var app = angular.module('app', ['ui.bootstrap']);
app.controller('ctl', function ($scope,$uibModal) {
$scope.queryList = function(query) {
return [ {id: 1, name: "aaa"},
{id: 2, name: "bbb"},
{id: 3, name: "ccc"}]
};
$scope.changeName = function(){
$scope.ds.name = "New name";
};
});
试试这个:
<input type="text" ng-model="ds.name"
uib-typeahead="ds as ds.name for ds in queryList($viewValue)" >
这是解决方案 - 重新创建整个对象:
$scope.changeName = function(){
$scope.ds = {
id: $scope.ds.id,
name: "New name"
};
};
要复制问题 in this plunk,请在字段中输入任何内容,select 任意行,然后单击按钮 "Change Name"。您会看到模型已更改,但 Angular 提前输入字段不反映模型。有什么想法吗?
HTML
<input type="text" ng-model="ds"
uib-typeahead="ds as ds.name for ds in queryList($viewValue)" >
<p>Model: {{ds}}</p>
<button ng-click="changeName()">Change Name</button>
Javascript
var app = angular.module('app', ['ui.bootstrap']);
app.controller('ctl', function ($scope,$uibModal) {
$scope.queryList = function(query) {
return [ {id: 1, name: "aaa"},
{id: 2, name: "bbb"},
{id: 3, name: "ccc"}]
};
$scope.changeName = function(){
$scope.ds.name = "New name";
};
});
试试这个:
<input type="text" ng-model="ds.name"
uib-typeahead="ds as ds.name for ds in queryList($viewValue)" >
这是解决方案 - 重新创建整个对象:
$scope.changeName = function(){
$scope.ds = {
id: $scope.ds.id,
name: "New name"
};
};