Javascript 重写传递给angularjs中指令的函数对象或访问实例方法中的方法
需要有关传递给指令的函数对象的JavaScript继承的帮助。 这是我的指令函数对象,该函数被传递给angular.directiveJavascript 重写传递给angularjs中指令的函数对象或访问实例方法中的方法,javascript,angularjs,Javascript,Angularjs,需要有关传递给指令的函数对象的JavaScript继承的帮助。 这是我的指令函数对象,该函数被传递给angular.directive function DDDirective (){ return { restrict: 'EA', replace: 'true', templateUrl: 'template/abstractLazyLoad.html',
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);
对于指令
直接的渴望
我想在$scope.lazyLoad中添加更多属性,请告诉我如何添加。
我尝试使用JavaScript原型继承,但在控制器函数中,我无法访问DDDirective实例方法。这几乎不是规定的“角度方法”,但这应该满足您的要求:
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));
您应该授予对$scope的访问权,否则将无法从getProps异步加载属性。。我没有能量毛巾,你的答案很容易改变以适应它。将getProps更改为scopeAvailable$scope。