在angularjs中重载传递给指令的函数对象或访问实例方法中的方法
override a method in function object or access instance methods which is passed to a directive in angularjs
需要JavaScript帮助来继承传递给指令的函数对象。这是我的指令函数对象,这个函数被传递给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。懒汉,请告诉我怎么做。我尝试使用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));
相关文章:
- 创建对象函数原型和代码是错误的
- JavaScript模块模式-如何在使用对象/函数之前激发构造函数/init函数
- 如何从onclick字符串中引用javascript对象函数
- 更改对象函数仅用于示例
- javascript和jQuery的嵌套对象函数中的变量范围
- 将对象函数传递给请求动画帧时丢失对象引用
- 对象函数返回函数而不是值
- 使用onclick调用属性对象函数
- javascript拉斐尔对象函数传递
- 如何从onClick事件调用对象函数
- 可以't获取具有“t”的对象变量;这个“;由setTimeout()函数调用的对象函数中的属性
- 对象没有't继承父对象函数
- 调用父对象函数
- "这个“;对象函数内部的引用
- 将变量添加到对象函数调用的末尾
- 传单错误:对象函数没有方法'createIcon'在LayerGroup中创建自定义图标标记时
- TypeError:对象函数Object(){〔本机代码〕}没有方法'方法'
- 挖空 - 单击绑定到对象函数 - 范围问题
- 类型错误: 对象函数...没有方法“打开”
- JavaScript 对象函数