Angularjs 角度引导后的角度添加指令
我使用的是ngMeteor(Angular for Meteor),我成功地添加了Angularjs 角度引导后的角度添加指令,angularjs,meteor,Angularjs,Meteor,我使用的是ngMeteor(Angular for Meteor),我成功地添加了控制器,过滤器,服务,使用了它们相应的提供者(例如$controllerProvider和函数寄存器())。在指令中是否有相反的部分?我找不到任何类似于使用$compileProvider的方法 $compileProvider.directive('myDirective', function () { return function (scope, element, attrs) { // link
控制器
,过滤器
,服务
,使用了它们相应的提供者(例如$controllerProvider
和函数寄存器()
)。在指令中是否有相反的部分?我找不到任何类似于使用$compileProvider的方法
$compileProvider.directive('myDirective', function () {
return function (scope, element, attrs) {
// link function body
};
});
我一直在玩弄如何通过角度来动态加载所有东西,最后我终于让它大部分工作起来了。这是正确的。您必须使用
$compileProvider
,但它需要更多。我无法让它工作,除非我在config
中获得$compileProvider
,这是在引导过程中。我敢打赌,还有其他方法。例如,您可能还可以通过$injector
服务等获得它
:
var app = angular.module('app', []);
app.config(function($controllerProvider, $compileProvider) {
// see page 12 of:
// http://www.slideshare.net/nirkaufman/angularjs-lazy-loading-techniques
app.lazyController = $controllerProvider.register;
// see: http://jsfiddle.net/8Bf8m/33/
app.lazyDirective = $compileProvider.directive;
});
// ... time passes ...
app.lazyDirective('clickMe', function () { return {
link : function (scope, element) {
element.bind('click', function () {
alert('Clicked: ' + element.text());
});
},
};});