Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.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
Angularjs 角度-指令-保留父范围加属性值_Angularjs_Angularjs Directive - Fatal编程技术网

Angularjs 角度-指令-保留父范围加属性值

Angularjs 角度-指令-保留父范围加属性值,angularjs,angularjs-directive,Angularjs,Angularjs Directive,因此,我希望编写一个显示给定结构的指令。这些结构可以相互嵌入,因此指令只需在结构中读取,就可以找到其所有子级并相应地显示它们。如果其中一个子结构是另一个结构,则将使用新结构再次调用该指令 这是相当标准的,但是我不想创建新的作用域,因为我需要从主作用域调用函数 我是否可以保留原始范围并仍然通过属性传递信息?还有别的方法吗 我所做的工作如下: 使用原始结构调用structureContent指令 指令是一个模板,它根据结构的类型显示结构的属性。然后它得到它的子元素,如果其中一个子元素是一个结构,则再

因此,我希望编写一个显示给定结构的指令。这些结构可以相互嵌入,因此指令只需在结构中读取,就可以找到其所有子级并相应地显示它们。如果其中一个子结构是另一个结构,则将使用新结构再次调用该指令

这是相当标准的,但是我不想创建新的作用域,因为我需要从主作用域调用函数

我是否可以保留原始范围并仍然通过属性传递信息?还有别的方法吗

我所做的工作如下:

  • 使用原始结构调用structureContent指令
  • 指令是一个模板,它根据结构的类型显示结构的属性。然后它得到它的子元素,如果其中一个子元素是一个结构,则再次调用该指令
  • 就像我说的,这不是问题所在。问题是我还需要保留原来的作用域,因为我需要从那里调用函数
  • 我不能简单地调用父对象,因为可能有多个层次的嵌入式结构
  • 谢谢

    HTML

    模板调用

    <div layout="column" 
     flex="100"
      class="itemListSection" >
    
    <div class="md-3-line"
         ng-if="structObj.vartype=='6'" 
         ng-click="vm.currentStructure=scope.thisObj; vm.currentSubItem=scope.thisObj;"
         layout="row">
        <for-loop-list structObj="structObj" layout-fill></for-loop-list>
    </div>
    
    <div class="md-3-line"
         ng-if="structObj.vartype=='7'" 
         ng-click="vm.currentStructure=scope.thisObj; vm.currentSubItem=scope.thisObj;"
         layout="row">
        <while-loop-list structObj="structObj" layout-fill></while-loop-list>
    </div>
    
    <div class="md-3-line"
         ng-if="structObj.vartype=='8'" 
         ng-click="vm.currentStructure=scope.thisObj; vm.currentSubItem=scope.thisObj;"
         layout="row">
        <if-else-loop-list structObj="structObj" layout-fill></if-else-loop-list>
    </div>
    
    <div 
        ng-repeat="thisObj in vm.cadwolf_worksheet | orderBy:'location' track by thisObj.itemid" 
        ng-switch on="thisObj.vartype" 
        ng-if="thisObj.parentid==structObj.itemid" 
        class="subSection"
        ng-click="vm.currentSubItem=thisObj; vm.currentStructure=thisObj" >
    
            <div ng-switch-when="3"><equation-list equationobject="structObj"></equation-list></div>
            <div ng-switch-when="6"><structure-content structObject="thisObj"></structure-content></div>
            <div ng-switch-when="7"><structure-content structObject="thisObj"></structure-content></div>
            <div ng-switch-when="8"><structure-content structObject="thisObj"></structure-content></div>
    
    </div> 
    
    
    

    (function ()
    {
    'use strict';
    
    angular
        .module('app.core')
        .directive('structureContent', structureContent);
    
    /** @ngInject **/
    function structureContent($templateRequest, $compile)
    {   return {
            restrict : 'E',
    
            controller : ["$scope", "$element", "$attrs",
    
                function($scope, $element, $attrs) {
    
    
                    $scope.$watch($attrs.struct, 
    
                        function(){
    
                            $scope.structObj = $attrs.struct;
                        }
    
                    );
    
                }
            ],
    
            link : function(scope, element, attrs){
    
                $templateRequest("app/main/apps/document/worksheet/views/templates/multSpec/structureContentSection.html").then(function(html){
                    var template = angular.element(html);
                    element.html(template);
                    $compile(template)(scope);
                });
            }
        }
    }; 
    })();
    
    <div layout="column" 
     flex="100"
      class="itemListSection" >
    
    <div class="md-3-line"
         ng-if="structObj.vartype=='6'" 
         ng-click="vm.currentStructure=scope.thisObj; vm.currentSubItem=scope.thisObj;"
         layout="row">
        <for-loop-list structObj="structObj" layout-fill></for-loop-list>
    </div>
    
    <div class="md-3-line"
         ng-if="structObj.vartype=='7'" 
         ng-click="vm.currentStructure=scope.thisObj; vm.currentSubItem=scope.thisObj;"
         layout="row">
        <while-loop-list structObj="structObj" layout-fill></while-loop-list>
    </div>
    
    <div class="md-3-line"
         ng-if="structObj.vartype=='8'" 
         ng-click="vm.currentStructure=scope.thisObj; vm.currentSubItem=scope.thisObj;"
         layout="row">
        <if-else-loop-list structObj="structObj" layout-fill></if-else-loop-list>
    </div>
    
    <div 
        ng-repeat="thisObj in vm.cadwolf_worksheet | orderBy:'location' track by thisObj.itemid" 
        ng-switch on="thisObj.vartype" 
        ng-if="thisObj.parentid==structObj.itemid" 
        class="subSection"
        ng-click="vm.currentSubItem=thisObj; vm.currentStructure=thisObj" >
    
            <div ng-switch-when="3"><equation-list equationobject="structObj"></equation-list></div>
            <div ng-switch-when="6"><structure-content structObject="thisObj"></structure-content></div>
            <div ng-switch-when="7"><structure-content structObject="thisObj"></structure-content></div>
            <div ng-switch-when="8"><structure-content structObject="thisObj"></structure-content></div>
    
    </div>