私はAngular.jsのインラインテンプレートを試しています。 私は、HTMLページがレンダリングされるたびに、コンソールに印刷することによってAngularオブジェクトをデバッグする方法を知りたいと思います。Angular.js inline-templateのscriptタグからconsole.logに印刷するには?
インラインテンプレートは、スクリプトタグ内にhtmlテンプレートを配置します。例:
<script type="text/ng-template" id="/htmlpage.html">
<div class="page-header">
<h1>Title</h1>
</div>
<!-- everything else here is html too -->
</script>
スクリプトタグ内の要素が本当にJavaScriptではないので、やっかいです。 これで、htmlpage.html内のコンソールにinline-templateで印刷する方法がわかりません。
私が試みたが、スクリプトタグを入れ子にして失敗した:
<script type="text/ng-template" id="/htmlpage.html">
<!-- html page template Angular stuff before is okay -->
<script>console.log("this line DOESN'T SHOW UP anywhere");</script>
<!-- html page template Angular stuff AFTERWARDS ALL FAIL-->
</script>
それは、スクリプトタグ内ですので、私はまた、単に裸にconsole.logに投げてみました。
<script type="text/ng-template" id="/htmlpage.html">
<!-- rest of html page template is okay -->
console.log("this entire line gets output as text on the html page");
<!-- rest of html page template is okay -->
</script>
console.log("this entire line gets output as text on the html page");
の行全体が、コンソールではなくhtmlページに印刷されます。
テキストを.jsファイルの$ scopeに追加してからhtml add {{$ scope.WhatEverTextYouWant}} – user4321