ngRepeat 在 AngularUI 引导对话框中不起作用 [英] ngRepeat does not work inside AngularUI bootstrap dialog

查看:34
本文介绍了ngRepeat 在 AngularUI 引导对话框中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道如何让我的代码工作.我正在尝试创建用户创建对话框并希望使用 ngResource 发送发布数据,我已经配置了我的 PHP 后端并按预期工作.现在,我的问题是在对话框中附加错误,我尝试添加虚拟数据,但 ngRepeat 对我不起作用.我也尝试了不同的步骤来调试问题,但对我来说没有任何效果.我也在研究这个问题,但没有运气.这是我的代码:

<li ng-repeat="error in dialog.errors">{{ error }}</li>

试试看链接http://jsfiddle.net/QCQrF/

解决方案

@Ryan 在您的 jsFiddle 中发生了很多事情,但最重要的问题是您指定对话框模板的方式.模板可以指定为字符串(使用 template 属性)或部分(templateUrl).

如果您将模板移动到部分,您可以按如下方式指定它:

var dialogOpts = {背景:真实,键盘:真的,背景淡入淡出:真实,背景点击:真实,templateUrl: '登录对话框.html',控制器:'DialogCtrl',解析:{ dialogScope :{错误:['error1','error2'],title :'添加用户',btnTxt : '创建用户'}}};

此外,IMO 使用 resolve 属性而不是使用对话框的实例来传递要在对话框范围内公开的数据更容易.

我已将您的小提琴转换为 plunk 以显示此内容:http://plnkr.co/edit/iGIwPBj9zBPgX3IUwBNj?p=预览

您可能会发现 $dialog 的服务附加文档有助于进一步探索此服务:https://github.com/angular-ui/bootstrap/blob/master/src/dialog/README.md

作为最后一句话,我注意到您正在将 $event 参数传递给事件处理程序(所有对它们调用 preventDefault() ),而这是不必要.

does anyone know how to get my code working. I'm trying to make a user creation dialog and want to send post data using ngResource, I've already configured my PHP backend and its working as expected. Now, my problem is appending errors on the dialog, I've tried adding dummy data but ngRepeat does not work for me. I've also tried different steps debugging the problem but nothing works for me. I've also researching about the issue but no luck. here is my code:

<div name="errors" id="errors" class="alert alert-error">
        <li ng-repeat="error in dialog.errors">{{ error }}</li>
</div>

try to look at the link http://jsfiddle.net/QCQrF/

解决方案

@Ryan there were number of things going on in your jsFiddle but the most important problem was the way you were specifying dialog's template. A template can be either specify as string (using the template property) or as a partial (templateUrl).

If you move a template to a partial you can specify it like follows:

var dialogOpts = {
        backdrop: true,
        keyboard: true,
        backdropFade: true,
        backdropClick: true,
        templateUrl:  'login-dialog.html',
        controller: 'DialogCtrl',
        resolve: { dialogScope : {
          errors : ['error1', 'error2'],
          title :'Add User',
          btnTxt : 'Create User'
        }}
    };

Also, IMO it is easier to pass data to be exposed on the dialog's scope using the resolve property instead of using dialog's instance.

I've converted your fiddle to a plunk to show this: http://plnkr.co/edit/iGIwPBj9zBPgX3IUwBNj?p=preview

You might find $dialog's service additional documentation helpful in further exploaration of this service: https://github.com/angular-ui/bootstrap/blob/master/src/dialog/README.md

As the last remark, I've noticed that you are were passing the $event argument to event handlers (all calling preventDefault() on them) while this is unnecessary.

这篇关于ngRepeat 在 AngularUI 引导对话框中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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