【发布时间】:2017-07-19 12:24:20
【问题描述】:
要复制问题in this plunk,请在字段中输入任何内容,选择任意行,然后单击“更改名称”按钮。您将看到模型已更改,但 Angular Type-ahead 输入字段未反映模型。有什么想法吗?
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";
};
});
【问题讨论】:
-
改用
ng-model="ds.name":plnkr.co/edit/zaRdpKjfc6YhErVmkayi?p=preview -
我不能,因为我需要模型具有 id 和名称
标签: angularjs angular-ui-bootstrap angular-ui