[英]AngularJS directive is not getting data passed in scope
這是我的html片段:
<div ng-controller="ctrl"> <custom-tag title = "name" body = "content"> </custom-tag> </div>
這是編寫的控制器和指令:
var mod = angular.module("main_module",[]); //Controller mod.controller("ctrl",function($scope) { $scope.name="Page Title"; $scope.content="sample_template.html"; }); //Directive mod.directive("customTag", function() { return { 'restrict' : 'E', 'scope' : { 'title' : '=', 'body : '=' }, 'templateUrl' : 'directive_template.html' }; });
<!-- directive_template.html --> <div> <div>{{title}}</div> <div ng-include="'{{body}}'"></div> </div>
指令呈現的實際html是這樣的:
<div> <div ng-binding></div> <!-- ngInclude: '{{body}}' --> </div>
顯然,它不是從<custom_tag>
屬性獲取指令范圍變量的
請告訴我為什么會這樣,以及我如何解決此問題。 謝謝
檢查控制台是否有錯誤,多余的引號和大括號{{}}引起了錯誤。
<div> <div>{{title}}</div> <div ng-include="body"></div> </div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.