使用装饰器的正确方法 angularjs
correct way to use decorators angularjs
我正在使用 angular-bootstrap-日历存储库,文档允许我添加自定义模板,只需添加
app.config(function($provide) {
$provide.decorator('mwlCalendarDayDirective', function($delegate) {
var directive = $delegate[0];
delete directive.template; //the calendar uses template instead of template-url so you need to delete this
directive.templateUrl = 'path/to/my/slide/box/template.html';
return $delegate;
});
});
这对我来说很好,但我的问题是,要替换为另一个模板,它会保留相同的控制器吗?
是的,这样修饰指令是完全没问题的,它们只是带有 Directive
后缀的服务,包含 DDOs 的数组(按注册顺序)。此方法修改指定的属性,同时保持 DDO 的其余部分完好无损。
除了 compile
/ (post)link
/ pre
(link),修补起来有点棘手。
我正在使用 angular-bootstrap-日历存储库,文档允许我添加自定义模板,只需添加
app.config(function($provide) {
$provide.decorator('mwlCalendarDayDirective', function($delegate) {
var directive = $delegate[0];
delete directive.template; //the calendar uses template instead of template-url so you need to delete this
directive.templateUrl = 'path/to/my/slide/box/template.html';
return $delegate;
});
});
这对我来说很好,但我的问题是,要替换为另一个模板,它会保留相同的控制器吗?
是的,这样修饰指令是完全没问题的,它们只是带有 Directive
后缀的服务,包含 DDOs 的数组(按注册顺序)。此方法修改指定的属性,同时保持 DDO 的其余部分完好无损。
除了 compile
/ (post)link
/ pre
(link),修补起来有点棘手。