是否可以将ng-view设置为replace:true? [英] Is it possible to set ng-view to replace: true?

查看:95
本文介绍了是否可以将ng-view设置为replace:true?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Angular集成到Web应用程序中,并且我注意到包装器将页面上的某些CSS弄乱了.在研究了指令之后,我看到自定义指令可以将名为"replace"的属性设置为true,以便templateUrl直接替换而不是包装在指令的标记中.

I'm integrating Angular into a web application and I noticed that the wrapper is messing with some of the CSS on the page. After researching into directives, I saw that custom directives can have a property called 'replace' to be set to true so that the templateUrl directly replaces instead of being wrapped in the directive's tags.

是否可以使用ng-view(或更笼统地说是任何Angular指令)执行相同的操作?感谢您的帮助!

Is there a way to do the same with ng-view, or more generally any Angular directive? Thanks for the help!

推荐答案

我认为您最好的选择是装饰原始的ng-view指令并向其中添加replace:true开关.请注意,替换将被-呵呵-在下一个主要版本的angularjs中被替换,但是现在,它将起作用:

I think your best bet is to decorate the original ng-view directive and add the replace:true switch to it. Note, replace is going to be - hah - replaced in the next major version of angularjs, but for now, this will work:

app.config(function($provide) {
    $provide.decorator('ngViewDirective', function($delegate) {
        var directive = $delegate[0];
        directive.replace = true;

        return $delegate;
    });
});

当然还有jsFiddle:此处

And of course, the jsFiddle: Here

这篇关于是否可以将ng-view设置为replace:true?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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