AngularJS - rendering multiple lines and HTML files in one tag

I want to display template files (view + controller) and several html lines together in one tag. - I have several lines, for example

<p>some text</p>

and html files + controller, for example

template.html + template.controller.js

I want to display lines and template.html in one tag.

I already linked the html lines and I can make them with

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

Is it possible to serialize html files and display them in ng-bind-html? These files have their own controllers:

<div ng-controller="sampleCtrl">

Would they lose functionality?

NOTE: the order of the elements is important! For example, I want to display a line, then the contents of a file, and then again a line.

Thank you so much!

0
source share
1 answer

. html js . scope.someText , .

 <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:

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

, . , , , .

+2

Source: https://habr.com/ru/post/1598751/


All Articles