簡體   English   中英

組件類型角度指令ng-template

[英]Component type angular directive ng-template

在下面的代碼中,

<!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);

自定義指令my-info-msg不會在<div my-info-msg> </div>添加模板<strong>{{o.msg}}</strong> <div my-info-msg> </div>

請幫我!!!

正如@ emil.c指出的那樣。 您的代碼中有拼寫錯誤:

templateUrl: "my-info-msg.html"

template1Url刪除“1”時,它可以正常工作。

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

template1Url有一個拼寫錯誤,刪除templateUrl之間的1 ,你應該沒問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM