Html 在angular js中的指令中获取属性值

Html 在angular js中的指令中获取属性值,html,angularjs,angularjs-directive,Html,Angularjs,Angularjs Directive,我有指示 configModule.directive('iMemoryDiv',function () { return { restrict: 'E', scope: {}, replace: true, templateUrl: '/memoryDiv.html', link: function(scope, el, attrs) { scope.iObj

我有指示

 configModule.directive('iMemoryDiv',function () {

return {
        restrict: 'E',
        scope: {},
        replace: true,
        templateUrl: '/memoryDiv.html',
        link: function(scope, el, attrs) {              
            scope.iObj = scope.$parent[attrs.bIObject];     
            if(angular.isDefined(scope.iObj)){                    
                getSummary(scope.iObj);
            }
            function getSummary(iObj){
            }


        }
    };
}
))

我通过传递一个对象属性从html调用它

 <i-memory-div b-i-object="app"></i-memory-div> //here app is declared in a respective controller 
//此处应用程序在各自的控制器中声明
但是,此处指令在分配“app”值的控制器之前加载。因此,
scope.iObj=scope.$parent[attrs.bIObject]
总是给我未定义的值。

如何在分配应用程序值后加载指令???

您可以为指令指定一个独立的作用域,并将BioObject添加为作用域属性:

scope: {
            bIObject: '=',
        },

然后,您可以将代码放入控制器:而不是链接:

在链接功能中使用$observe服务,如下所示

if(attrs. bIObject) {
   attrs.$observe('bIObject', function(value) {
   console.log(value);
   })
}

这样做不是更容易吗:

configModule.directive('iMemoryDiv',function () {

return {
    restrict: 'E',
    scope: {
        'bIObject': '=',
        'getParentObject': '&'
    },
    replace: true,
    templateUrl: '/memoryDiv.html',
    link: function(scope, el, attrs) {
        scope.$watch('bIObject', function(newValue) {
            if(angular.isDefined(newValue)) {
               getSummary(scope.getParentObject({name: newValue}));
            }
        });
        function getSummary(iObj){
        }
    }
};
}

或者您是否需要从父范围中获取更多信息???

将BioObject设置为BioObject..如上所述(现在)。。。而且在html中,重新检查结束标记,它被错误地拼写为而不是