需要帮助传递给指令的函数对象的JavaScript继承。 这是我的指令函数Object,这个函数传递给angular.directive
function DDDirective (){
return {
restrict: 'EA',
replace: 'true',
templateUrl: 'template/abstractLazyLoad.html',
scope:{
id:'@idAttr'
},
controller:function($scope){
$scope.lazyLoad=funclazyLoadprops();
}
}
}
function funclazyLoadprops(){
return {
showText: "Show Divisional Directors",
hideText: "Hide Divisional Directors",
templateName: 'template/dd/main.html'
}
}
app.directive('ddDirectiveLazy', DDDirective);
app.directive('ddDirectiveEager',DDDirective);
指令
ddDirectiveEager
我想在$ scope.lazyLoad中添加更多属性,请告诉我如何操作。 我试图使用JavaScript原型继承,但在控制器函数中我无法访问DDDirective实例方法。
答案 0 :(得分:0)
这不是规定的“角度方式”,但这应该按照你的要求行事:
function DDDirective (getProps){
return function(){
return {
restrict: 'EA',
replace: 'true',
templateUrl: 'template/abstractLazyLoad.html',
scope:{
id:'@idAttr'
},
controller:function($scope){
$scope.lazyLoad = getProps();
}
};
};
}
function funclazyLoadprops(){
return {
showText: "Show Divisional Directors",
hideText: "Hide Divisional Directors",
templateName: 'template/dd/main.html'
}
}
function funcEagerLoadprops(){
var lazyprops = funclazyLoadprops();
//attach additional properties here
return lazyprops;
}
app.directive('ddDirectiveLazy', DDDirective(funclazyLoadprops));
app.directive('ddDirectiveEager',DDDirective(funcEagerLoadprops));