简体   繁体   English

在Angular JS中动态加载视图/控制器

[英]Dynamically loading views / controllers in Angular JS

We are developing an configuration tool using Angular.JS. 我们正在使用Angular.JS开发配置工具。 The GUI contains 2 sections - a left panel which contains a tree view, which list all the configuration items and a right panel which contains screens using which configuration items can be edited . GUI包含2个部分-左侧面板包含树视图,列出所有配置项目,右侧面板包含包含可编辑配置项目的屏幕的屏幕。 There are about 6 or 7 different types of configuration items and each of them contains different views... 大约有6或7种不同类型的配置项,每个配置项包含不同的视图...

Currently we have a single view and controller because a single API call fetches all the data. 当前,我们只有一个视图和控制器,因为单个API调用会提取所有数据。 Each configuration screen is a div tag which is shown / hidden where the tree node is clicked... The code is becoming more cluttered... Is there any way to separate each configuration screen as a separate view / controller and dynamically with out using routing 每个配置屏幕都是一个div标记,在单击树节点的位置会显示/隐藏该代码...代码变得越来越混乱...有没有办法将每个配置屏幕作为一个单独的视图/控制器进行分离,并且无需使用路由

What about ng-include? ng-include呢?

<div ng-include="view1.html" ng-if="selected == 1">
<div ng-include="view2.html" ng-if="selected == 2">
<div ng-include="view3.html" ng-if="selected == 3">

And in each html u can specify own controller etc. 并且在每个html中,您都可以指定自己的控制器等。

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

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