在 angular.dart 中使用 select 指令的正确方法是什么 [英] What is right way to use select directive in angular.dart

查看:25
本文介绍了在 angular.dart 中使用 select 指令的正确方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用基本的 CRUD 操作扩展了 angular.dart.tutorial.因此,在新的 edit_recipe_component.html 中,我需要为配方类别添加某种选择输入.

I extend angular.dart.tutorial with basic CRUD operations. So in new edit_recipe_component.html I need to add some sort of selection input for recipe categories.

目前我有

<select ng-model="ctrl.recipe.category">
   <option ng-repeat="c in ctrl.categories" value="{{c}}">{{c}}</option></select>

表面上效果很好:我可以从列表中选择类别,所选类别已成功存储在模型中等等.但我在调试控制台中收到这些错误:

That works perfectly well on the surface: I can select category from the list, selected category is successfully stored in model and so on. But I get these errors in debug console:

NoSuchMethodError : method not found: 'ngValue'
Receiver: null
Arguments: []

STACKTRACE:
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:42)
#1      _SingleSelectMode.onModelChange.<anonymous closure> (package:angular/directive/input_select.dart:185:78)
#2      _SelectMode._forEachOption (package:angular/directive/input_select.dart:146:24)
#3      _SingleSelectMode.onModelChange (package:angular/directive/input_select.dart:183:19)

我做错了什么?

不幸的是 APIDOCS 到 InputSelectDirective 没有使用部分

Unfortunately APIDOCS to InputSelectDirective has no usage section

更新:我根据第 6 章示例创建了 github 项目,其中重现了问题它在这里:https://github.com/vadimtsushko/angular_tutorial_chapter_06

Update: I've created github project based on Chapter 6 sample where problem is reproduced It is here: https://github.com/vadimtsushko/angular_tutorial_chapter_06

一些调试显示,在编辑表单中设置类别可以立即并成功地工作(为了调试目的,我在食谱列表视图中添加了类别).离开编辑表单时出现错误.

Some debugging shows that setting category in Edit form works immediately and successfully (I've added category in Recipes list view for debug purpose). Error raised when I leave Edit form.

推荐答案

我相信这个问题已经修复了一段时间(因此不需要补丁),但无论如何,你也可以使用 ng值:

I believe that this issue has been fixed for a while (hence no need for a patch), but in any case, you could also have used ng-value:

<select ng-model="ctrl.recipe.category">
   <option ng-repeat="c in ctrl.categories" ng-value="c">{{c}}</option></select>

这篇关于在 angular.dart 中使用 select 指令的正确方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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