Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/462.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 重写传递给angularjs中指令的函数对象或访问实例方法中的方法_Javascript_Angularjs - Fatal编程技术网

Javascript 重写传递给angularjs中指令的函数对象或访问实例方法中的方法

Javascript 重写传递给angularjs中指令的函数对象或访问实例方法中的方法,javascript,angularjs,Javascript,Angularjs,需要有关传递给指令的函数对象的JavaScript继承的帮助。 这是我的指令函数对象,该函数被传递给angular.directive function DDDirective (){ return { restrict: 'EA', replace: 'true', templateUrl: 'template/abstractLazyLoad.html',

需要有关传递给指令的函数对象的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);
对于指令

直接的渴望

我想在$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。