AngularJS - 渲染多个字符串和HTML文件中的一个标签 [英] AngularJS - Render multiple strings and HTML files in a single tag

查看:225
本文介绍了AngularJS - 渲染多个字符串和HTML文件中的一个标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要呈现无论是在单个标签一起模板文件(查看+控制器)和多个HTML字符串。
- 所以,我有一些字符串如

I want to render template files (view + controller) and multiple html strings both together in a single tag. - So I have some strings like

<p>some text</p>

和HTML文件+控制器像

and html files + controller like

template.html + template.controller.js

我要的字符串和template.html渲染成一个标签。

I want to render the strings and the template.html into one tag.

我已经连接的HTML字符串和我能够使这些以

I already connected the html strings and I'm able to render these with

<div ng-bind-html="template" ..></div>

我可以序列化的HTML文件和NG绑定HTML的渲染它吗?这些文件有自己的控制器:

Can I serialize the html files and render it in ng-bind-html too? These files have own controllers:

<div ng-controller="sampleCtrl">

他们会失去功能?

They would lose functionality?

注:元素的顺序是重要!!!例如,我想然后再次渲染字符串,则该文件的内容和一个字符串

NOTE: The order of the elements is important!!! For example, I want to render the string, then the content of the file and then again a string.

非常感谢!

推荐答案

您应该使用指令。这将允许您加载一个HTML文件关联的js文件。您可以在指令设置scope.someText和例如叫它视图

You should use directives. This will allow you to load a html file with an associated js file. You can set scope.someText in the directive and call it in the view e.g.

 <p>{{someText}}</p>

指令:

var app = angular.module('myApp');

app.directive('someTextDirective', function(){
    return{
         restrict: 'E',
         templateUrl: 'path/to/html/file.html',
         link:function(scope){
              scope.someText = 'blah';
         }
    }
});

只需调用指令,在您的HTML:

Simply call the directive in your html:

<some-text-directive></some-text-directive>

希望这有助于。如果我一直没明确告诉我,我会尽我所能来澄清一下。

Hope this helps. If I have not been clear let me know and I will do my best to clarify.

这篇关于AngularJS - 渲染多个字符串和HTML文件中的一个标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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