2017-06-15 3 views
1

私はちょうど角度のついた指示で遊んでいますが、何とか指示を加えるコメントの方法は表示されません。ここにマークアップがあります。 template.htmlでAngularJSの指示としてのコメント

<!DOCTYPE html> 
<html> 
<head> 
    <title></title> 
    <script src="angular.js"></script> 
</head> 

    <body ng-app="directive-app"> 

     <first-directive></first-directive> 

     <div first-directive></div> 

     <div class=first-directive></div> 

     <!-- directive: first-directive -->  

     <script src="main.js"></script> 


</body> 
</html> 

指令の定義

var app=angular.module('directive-app',[]); 

app.directive("firstDirective", function() { 
    return { 
     restrict : "EACM", 
     templateUrl : 'template.html' 
    }; 
}); 

1 H1要素があります。しかし、ディレクティブを追加するコメント方法はUIに表示されず、その場合にはコメントのアプローチも必要です。

答えて

3

設定truereplaceオプションdemoをだ。ここ

app.directive("firstDirective", function() { 
    return { 
    restrict: "EACM", 
    replace: true, 
    templateUrl: 'template.html' 
    }; 
}); 

を次のように。

+0

あなたはそのことについていくつかの説明をすることができます。コメントの場合に置換する必要があるのはなぜでしょうか? –

+0

@MahtabAlamまず、 'replace'オプションに精通してください.https://stackoverflow.com/a/15286383/87972を参照してください。 'replace'が' false'のとき、Angularはコメントの中にテンプレートの内容を入れようとします。それは目に見えません。 'replace'が' true'のとき、Angularはそのコメントをテンプレートの内容に置き換えます。それが目に見えます。 – Hoa

+0

ありがとうございます@Hoa –

関連する問題