2015-09-17 63 views
0

更新我有我的控制器這個方法:範圍模型不上選擇

$scope.selectEscalationResponsible = function($user, $model, $label) { 

     $scope.escalationResponsible = $user.user.first_name + ' ' + $user.user.last_name; 

    }; 

這種方法是由該輸入元素觸發:

<input class="form-control" 
        type="text" 
        ng-model="escalationResponsible" 
        typeahead-wait-ms="200" 
        select-text-on-focus 
        typeahead-editable="false" 
        typeahead="value as (user.user.first_name + ' ' + user.user.last_name) for user in oppType.team_settings.users" 
        typeahead-on-select="selectEscalationResponsible($item, $model, $label)"> 
       <small translate>Start typing a name from the list below</small> 

的方法被觸發,由輸入字段的值未被更新。 我不明白爲什麼。

回答

0

一切似乎工作正常。這裏有一個plunkr你看看 http://plnkr.co/edit/MnGM7ye8VV3jZ9G63RWc?p=preview

angular.module('ui.bootstrap.demo', ['ngAnimate', 'ui.bootstrap']); 
angular.module('ui.bootstrap.demo').controller('TypeaheadCtrl', function($scope, $http) { 

    $scope.users =[{user: {first_name: "test", last_name: "last"}},{user: {first_name: "test2", last_name: "last2"}}]; 

    $scope.selectEscalationResponsible = function($user, $model, $label) { 

     $scope.escalationResponsible = $user.user.first_name + ' ' + $user.user.last_name; 

    }; 

}); 





<!doctype html> 
<html ng-app="ui.bootstrap.demo"> 
    <head> 
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.js"></script> 
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular-animate.js"></script> 
    <script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.13.4.js"></script> 
    <script src="example.js"></script> 
    <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet"> 
    </head> 
    <body> 

<script type="text/ng-template" id="customTemplate.html"> 
    <a> 
     <img ng-src="http://upload.wikimedia.org/wikipedia/commons/thumb/{{match.model.flag}}" width="16"> 
     <span bind-html-unsafe="match.label | typeaheadHighlight:query"></span> 
    </a> 
</script> 
<div class='container-fluid' ng-controller="TypeaheadCtrl"> 
    <input class="form-control" 
        type="text" 
        ng-model="escalationResponsible" 
        typeahead-wait-ms="200" 
        select-text-on-focus 
typeahead-editable="false" 
        typeahead="value as (user.user.first_name + ' ' + user.user.last_name) for user in users" 
        typeahead-on-select="selectEscalationResponsible($item, $model, $label)"> 
{{escalationResponsible}} 
</div> 
    </body> 
</html> 
+0

我看到你的榜樣工作,但它只是沒有在我結束工作。 – Repox

+0

你可以創建一個plunkr嗎? –

+0

我不知道什麼是錯的。出於某種原因,我的代碼現在可以工作。 – Repox