attrs。$ set('ngClick',functionName +'()');不再工作角度为1.2rc3 [英] attrs.$set('ngClick', functionName + '()'); no longer working in angular 1.2rc3

查看:52
本文介绍了attrs。$ set('ngClick',functionName +'()');不再工作角度为1.2rc3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个开源项目,我正在升级到使用角度1.2rc3。基本上它处理表单按钮上的承诺。在这个plnkr http://plnkr.co/edit/vQd97YEpYO20YHSuHnN0?p=preview 你应该可以点击右侧的保存,看到控制台中出现点击,因为它应该在指令中执行此代码:

I have an open source project that I'm working on upgrading to work with angular 1.2rc3. Essentially it handles promises on form buttons. In this plnkr http://plnkr.co/edit/vQd97YEpYO20YHSuHnN0?p=preview you should be able to click "Save" on the right side and see a "clicked" appear in the console, because it should execute this code in the directive:

            scope[functionName] = function () {
                console.log('clicked');
                //if it's already busy, don't accept a new click
                if (scope.busy === true) {
                    return;
                }

                scope.busy = true;
                var ret = scope.$eval(onClick);
                if (angular.isDefined(ret) && ret.hasOwnProperty('then')) {
                    ret.then(function () {
                        scope.busy = false;
                    });
                }
            };

使用1.2时,尽管执行了以下代码,但此方法不再执行:

With 1.2, this method no longer gets executed despite the following code being executed:

            if (angular.isDefined(attrs.ngClick)) {
                console.log('test');
                attrs.$set('ngClick', functionName + '()');
            }

我无法弄清楚为什么这个功能无法获得执行....任何想法?

I haven't been able to figure out why this function won't get executed.... any ideas?

推荐答案

一些指令优先级已更改(请参阅重大更改)。这是一个更新的plunkr ,它只是在<$ c中为繁忙的按钮指令设置了一个负面优先级。 $ c> angular-form-ui.js 。

Some of the directive priorities have changed (see "Breaking Changes") in Angular 1.2. Here's an updated plunkr which simply sets a negative priority on your busy button directive in angular-form-ui.js.

restrict: 'A',
priority: -100, // <-- This is the only change I made
controller: ...

这会导致你的指令替换 ngClick 属性的值,在 ngClick 指令使用属性的值使用 $ parse <创建一个函数指针 / code> 。

This causes your directive, which replaces the value of the ngClick attribute, to execute before the ngClick directive uses the value of the attribute to create a function pointer using $parse.

这篇关于attrs。$ set('ngClick',functionName +'()');不再工作角度为1.2rc3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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