简体   繁体   中英

Component type angular directive ng-template

In the below code,

<!DOCTYPE html>
    <html>
        <head>
            .....
        </head>
        <body ng-app="app">
            <script type="text/ng-template" id="my-info-msg.html">
                <strong>{{o.msg}}</strong>
            </script>
            <div ng-controller="emp as o">
                <div my-info-msg>

                </div>  
            </div>
        </body>
    </html>

var app = angular.module("app", []);

function MyController(){
    this.msg= 'This is a message';
}
app.controller('emp', MyController);


function MsgDirective(){
    return{
        template1Url: "my-info-msg.html"
    };
}
app.directive('myInfoMsg', MsgDirective);

custom directive my-info-msg does not add the template <strong>{{o.msg}}</strong> in <div my-info-msg> </div> .

Please help me!!!

As @emil.c has pointed out. You have a typo in your code:

templateUrl: "my-info-msg.html"

It works fine when you remove the "1" from your template1Url .

https://plnkr.co/edit/Q20v7zSHHVPNJOOievrm?p=preview

template1Url有一个拼写错误,删除templateUrl之间的1 ,你应该没问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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