页面内加载AngularJS模板,动态 [英] Load AngularJS Template within page, dynamically

查看:133
本文介绍了页面内加载AngularJS模板,动态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含2个控制器的页面:一个用来管理所谓的应用程序列表,另一个是新角模板放入它的div元素的innerHTML

I have a page containing 2 controllers: one which manages a list of so-called 'apps', and another that is to place the new Angular template into the innerHTML of its Div element.

<div ng-controller="appList"></div>
<div ng-controller="appPane"> Dynamic content should be loaded here! </div>

我已经使用标准{{EX pression}}绑定尝试过,但他们不与HTML工作,我也曾尝试NG绑定HTML的不安全指令(绑定innerHTML来该应用程序的要求的回报),但控制器没有这个新的code内执行。

I have tried using the standard {{expression}} bindings, but they do not work with html, I have also tried the ng-bind-html-unsafe directive (Binding the innerhtml to that of the App request's return) but controllers are not executed within this new code.

的问题似乎是,通过使用绑定,角不重新解析有关的HTML内容,以将其用作角应用程式。如何得到它来解析动态内容的任何想法?

The problem seems to be that by using a Binding, Angular is not re-parsing the contents of the html in question to use it as an angular app. Any ideas of how to get it to parse dynamic content?

推荐答案

看看在 uiRouter 模块(从 AngularUI 项目)。它增加了国家,这是类似的路线pretty的概念,但与其他好吃的东西,如能力巢他们。例如:

Take a look at the uiRouter module (from the AngularUI project). It adds the concept of states, which are pretty similar to routes, but with other goodies, such as the ability to nest them. For example:

$stateProvider
    .state('myState', {
        url: '/mystate',
        templateUrl: '...',
        controller: 'MyCtrl'
    })
    .state('myState.substate', {
        url: '/{substate}',
        templateUrl: '...',
        controller: 'MySubCtrl'
    });

MySubCtrl 每当你去 / mystate /东西键,您可以使用东西作为将被激活参数(见 $ stateParams )。您可以嵌套国家级别的任何金额。

MySubCtrl will be activated whenever you go to /mystate/something and you can use that "something" as a parameter (see $stateParams). You can nest states to any amount of levels.

这篇关于页面内加载AngularJS模板,动态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆