Insert HTML into view from AngularJS controller

前端 未结 18 1787
Happy的楠姐
Happy的楠姐 2020-11-21 06:00

Is it possible to create an HTML fragment in an AngularJS controller and have this HTML shown in the view?

This comes from a requirement to turn an

18条回答
  •  独厮守ぢ
    2020-11-21 06:50

    there is one more solution for this problem using creating new attribute or directives in angular.

    product-specs.html

     

    Specs

    • Shine : {{product.shine}}
    • Faces : {{product.faces}}
    • Rarity : {{product.rarity}}
    • Color : {{product.color}}

    app.js

     (function() {
    var app = angular.module('gemStore', []);    
    app.directive("     
    ", function() { return { restrict: 'E', templateUrl: "product-specs.html" }; });

    index.html

     
    //it will load product-specs.html file here.

    or

    //it will add product-specs.html file

    or

    https://docs.angularjs.org/guide/directive

提交回复
热议问题