2016-12-30 62 views
1

我有一個下拉如何在Angularjs的contextscope中傳遞從下拉列表中選擇的值?

$scope.animals = [ 
     {value:'lion', name:'lion', description: 'lion'}, 
     {value:'cat', name:'cat', description: 'cat'}, 
     {value:'dog', name:'dog', description: 'dog'}, 
    ]; 

,我想通過從下拉菜單中選擇contextscope到其他配置參數的值。例如

​​

在描述型的指令,我將描述

<input ng-model="context.description" name="context.description"> 

我收到以下錯誤: 「無法在字符串新屬性‘說明’「獅子」

的我想要的JSON格式是

"lion" : { 
      "description": "wild animal" 
     } 

我該如何解決發現錯誤並創建JSON?

回答

0

您正在設置錯誤的值。 ngModel的值設置爲animal.value,在這種情況下,它是字符串獅子。相反,它應該是:

<md-select ng-model="context"> 
    <md-option ng-repeat="animal in animals" value="{{animal}}" aria-label="{{animal.name}}">{{animal.name}}</md-option> 
</md-select> 
<div described-type flex="70" contextscope="context"></div> 
相關問題