AngularJS TemplateUrl不绑定到$ scope

时间:2014-03-24 17:54:03

标签: angularjs data-binding

我知道之前已经问过这个问题,但是我看了他们所有人,却找不到任何东西。这基本上就是我所拥有的:

的layout.html

<html ng-app="myApp">
   ...
   <div my-container></div>
   ...
</html>

app.js

var App = angular.module('myApp', [] );
App.directive('myContainer', function(){
    return {
        restrict: 'A',
        replace: true,
        templateUrl: '/path/to/view.html',
        link: function(scope) {
            scope.param = 3; 
        }
    }
});

view.html

<div>
   {{ param }}
</div>

在运行时,view.html已加载,但我仍然看到{{ param }}。我真的不明白为什么!请指教。


这是我的确切代码。我正在使用Laravel和AngularJS。我的层次结构如下:

/app
   /app
      ... Laravel back-end, including the layout.blade.php
   /bootstrap
   /public
       /app
           /views
               miniCalendar.html
           /controllers
           /lib
           ...
           app.js
       index.php 

app.js

var App = angular.module('mainApp', [] );    
App.directive('miniCalendar', function() {
    return {
        restrict: 'A',
        replace: true,
        templateUrl: '/app/views/miniCalendar.html',
        link: function(scope) {
            scope.title = 'March'; // This is just an example.
    }
}

});

miniCalendar.html

<block mini-calendar class="full-content block mini-calendar" name="mini-calendar">
   <!-- Code here -->
   <span class="large-10 columns text-bold ti" ng-hide="hide" ng-click='headerToggle()'>{{ title }}</span>
   <!-- Code here -->
</block>

1 个答案:

答案 0 :(得分:0)

您的路径可能有误,我测试了您的代码并且有效,这是一个实例:http://plnkr.co/edit/d5rgPAj1nPIxcqSrqCD1?p=preview

相关问题