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