为什么NG-选择与吴先生中继工作? [英] Why does ng-selected not work with ng-repeater?

查看:123
本文介绍了为什么NG-选择与吴先生中继工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是为什么中继打破

 <选择名称=季度NG模型=季NG-选择=季>
    <选项NG重复=V在[1,2,3,4]VALUE ={{V}}>问{{V}}< /选项>
< /选择>

但不是手写的方式?

 <选择名称=季度NG模型=季NG变化=onQuarterChange()NG选择=季>
    <期权价值=1> Q1< /选项>
    <期权价值=2> Q2< /选项>
    <期权价值=3> Q3< /选项>
    <期权价值=4> Q4< /选项>
< /选择>


解决方案

坚持使用 NG-选项

 < D​​IV NG-应用>
  < H2>藤< / H>
  < D​​IV NG控制器=QuarterController>
    <选择名称=季度NG模型=季NG选项=obj.value作为obj.text在[{'值':1,'文字':'Q1'} OBJ,{'值'2,'文字':'Q2'},{'值':3,'文字':'Q3'},{'值':4,文:四季度'}]>
    < /选择>
  < / DIV>
< / DIV>功能QuarterController($范围){
    $ scope.Quarter = 2;
}

http://jsfiddle.net/hDNsm/3/

您不妨在你的控制器定义数组

Why is this repeater broken

<select name="quarter" ng-model="Quarter" ng-selected="Quarter" >
    <option ng-repeat="v in [1,2,3,4]" value="{{v}}">Q{{v}}</option>
</select>

But not the handwritten way?

<select name="quarter" ng-model="Quarter" ng-change="onQuarterChange()" ng-selected="Quarter">
    <option value="1">Q1</option>
    <option value="2">Q2</option>
    <option value="3">Q3</option>
    <option value="4">Q4</option>
</select>

解决方案

stick with ng-options

<div ng-app>
  <h2>Todo</h2>
  <div ng-controller="QuarterController">
    <select name="quarter" ng-model="Quarter" ng-options="obj.value as obj.text for obj in [{'value': 1,'text' : 'Q1'},{'value':2,'text':'Q2'},{'value':3,'text':'Q3'},{'value':4,'text':'Q4'}]">
    </select>
  </div>
</div>

function QuarterController($scope) {
    $scope.Quarter = 2;
}   

http://jsfiddle.net/hDNsm/3/

you might as well define the array in your controller

这篇关于为什么NG-选择与吴先生中继工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆