繁体   English   中英

如何在Angularjs的contextscope中传递从下拉列表中选择的值?

[英]How to pass the value selected from dropdown in contextscope in Angularjs?

我有一个下拉列表

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

我想将从dropdown中选择的值作为contextscope传递给另一个指令。 例如

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

在describe-type指令中,我正在添加描述

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

我收到以下错误:“无法在字符串'lion'上创建属性'描述'”

我想要的JSON格式是

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

如何解决错误并创建JSON?

你设置的值不正确。 ngModel设置为value,您设置为animal.value ,在这种情况下是字符串lion。 相反,它应该是:

<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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM