【问题标题】:Model is not refreshed in Angular UI type-ahead模型未在 Angular UI type-ahead 中刷新
【发布时间】: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";
    };

}); 

【问题讨论】:

标签: angularjs angular-ui-bootstrap angular-ui


【解决方案1】:

试试这个:

  <input type="text" ng-model="ds.name" 
    uib-typeahead="ds as ds.name for ds in queryList($viewValue)" >

【讨论】:

  • 我不能,因为我需要模型具有 id 和名称
【解决方案2】:

这是解决方案 - 重新创建整个对象:

$scope.changeName = function(){
  $scope.ds = {
    id: $scope.ds.id,
    name: "New name"
  };
};

PLUNK

【讨论】:

    猜你喜欢
    • 2016-09-05
    • 1970-01-01
    • 2014-03-14
    • 1970-01-01
    • 2015-06-09
    • 1970-01-01
    • 1970-01-01
    • 2017-06-10
    • 2018-02-09
    相关资源
    最近更新 更多