简体   繁体   English

动态创建元素上的角度模块

[英]Angular module on dynamically created elements

i have a existing controller and template: 我有一个现有的控制器和模板:

<div id="outputTableforApp" ng-controller="OutputTableModelCtrl">
    <div id ="outputtablemodel_panel" ng-show="editMode">
    </div>
</div>

it works perfectly. 它完美地工作。 But now i need to delete the template from the project (which has a fix place in the DOM) and somehow make it appear dynamically when man a button click. 但是现在我需要从项目中删除模板(该模板在DOM中有固定的位置),并在按一下按钮时以某种方式使其动态显示。 when i tried that with jQuery 当我尝试使用jQuery

$('<div id="outputTableforApp" ng-controller="OutputTableModelCtrl"><div id ="outputtablemodel_panel" ng-show="editMode">\n\
</div></div>').appendTo($('#div1'));

My Angular module didn't work at all. 我的Angular模块根本不起作用。 So i guess i need to register the module somehow again every time when someone presses the button, is that the case ? 所以我想我每次有人按下按钮时都需要重新注册模块,是这样吗? if so ,how could i do it ? 如果是这样,我该怎么办?

You can use ng-show so do this: 您可以使用ng-show这样做:

<div id="outputTableforApp" ng-controller="OutputTableModelCtrl" ng-show="showApp">

and when the button is clicked call a function (using ng-click ) in your controller script that makes it that showApp is true (make sure you use $scope.showApp in the function). 当单击按钮时, ng-clickcontroller脚本中调用一个函数(使用ng-click ),以确保showApptrue (确保在函数中使用$scope.showApp )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM