实际上,我想将控制器作用域值绑定或传递为angularjs自定义指令模板中的作用域名称。
在这里,我想提一下在控制器中动态形成的作用域名称,然后将值分配给该作用域(动态生成的作用域)。
指令代码:
app.directive('webTemplateCreation',function($compile,$timeout){
var layoutObj={};
linkFn=function(scope, element, attributes, controller) {
element.append("<web-template-layout ng-repeat='layout in layoutData.collections.layout.rowset' layout='layout'></web-template-layout>");
$compile(element.contents())(scope);
};
// isolated scope with layout data, mapper data and page object
layoutObj.scope={layoutData:'=',pageObject:'=',mapperData:'=', containerId:'='};
layoutObj.restrict='AE';
layoutObj.replace='true';
// template for creating the layout
layoutObj.template = "<div "
+ "page-object='[\"layoutObj\"].Data'"
+ "layout-data='[\"pageObj\"].Data'"
+ "mapper-data='mapperObject.Data' "
+ "container-id='templateContainerId' "
+ "style='height:100%;' class='row bootstrap480'>"
+ "</div>";
layoutObj.link = linkFn;
return layoutObj;
});
//范围未绑定/传递
[\“ layoutObj \”]-这不起作用。此范围来自控制器
希望我能正确解释。如果需要更多详细信息,请及时更新。
此方法是我在控制器中编写的,正在传递该对象。
$scope.getTemplateToRender = function(templateContainerId, entityName) {
$tempCEP.fetchLayoutDetailsForRendering(getAttributeName(entityName), function(layoutObject, pageObject, blocklyXML, entityTypeJSON) {
$scope.layoutObj = 'layoutObject'+templateContainerId;
$scope[$scope.layoutObj] = {};
$scope[$scope.layoutObj].Data = {};
$scope[$scope.layoutObj].Data = layoutObject;
$scope.pageObj = 'pageObject'+templateContainerId;
$scope[$scope.pageObj] = {};
$scope[$scope.pageObj].Data = {};
$scope[$scope.pageObj].Data = pageObject;
$scope.layoutState.state = 'new';
var entityType = 'website';
$scope.containerTemplate = true;
$scope.templateContainerId = templateContainerId;
if($scope.containerTemplate == true) {
var newElement = $compile("<web-template-creation></web-template-creation>")($scope);
angular.element("[containerid="+$scope.templateContainerId+"]").html("");
$element.find("[containerid="+$scope.templateContainerId+"]").append(newElement);
//$scope.$digest();
}
$scope.reinitialize();
});
};