简体   繁体   English

指令中的Angular Controller不绑定

[英]Angular Controller in Directive not binding

new to angular and appear to be stuck on the simplest of tasks. 刚接触过角度,似乎停留在最简单的任务上。 I have and existing application that I need to modify. 我有需要修改的现有应用程序。 I'm trying to add an additional tab to a page - the tab shows up but the content from my template does not - it also does not fire a consols.log I have in the controller 我正在尝试向页面添加其他选项卡-该选项卡显示但我模板中的内容不显示-它也不会触发控制器中的consols.log

Directive: 指示:

'use strict';

angular.module('bdrApp.admin.student-transfer-directive', [])
/* bdr-student-transfer
 */
.directive('bdrStudentTransfer', [function() {
    var controller = [
        function() {
            console.log("Hello, Student Transfer");
        }
    ];

    return {
        scope: {},
        restrict: 'E',
        controller: controller,
        templateUrl: 'res/templates/admin/studentTransfer.html?v1.0'
    };
}]);

Template: 模板:

<div  class="studentTransfer" ng-show="!loading">
    <div class="">
        <strong>Coming Soon!</strong>
    </div>


</div>

app.js app.js

  'bdrApp.admin.student-report-directive',

index.html index.html

    <script src="directives/admin/student-transfer-directive.js"></script>

adminview.html (where the tabs are defined) adminview.html(定义选项卡的位置)

    <div ng-switch-when="resource" class="admin-resource-view">
            <bdr-admin-resource-view ></bdr-admin-resource-view>
        </div>
        <div ng-switch-when="studentTransfer" class="admin-studentTransfer-view">
            <bdr-student-transfer></bdr-student-transfer>
        </div>

I solved the problem following the suggestion from orange to remove the ng-switch-when tag for troubleshooting. 我按照橙色的建议解决了问题,删除了ng-switch-when标签以进行故障排除。 This showed my template content on all the tabs and fired the console.log. 这在所有选项卡上显示了我的模板内容,并触发了console.log。 I then put the tag back in this time not using camelCase and keeping it all lower case - works! 然后,我这次不使用camelCase放回标签,而是将其全部保留为小写-可以!

If someone could comment as to why this is case sensitive that would be great. 如果有人可以评论为什么这是区分大小写的,那就太好了。

Thanks 谢谢

adminView.html: adminView.html:

 "<div ng-switch-when="studenttransfer" class="admin-studentTransfer-view">"

adminView.js adminView.js

   // Define tabs
  $scope.tabs = {
    students: {
      text: 'Manage Students',
      active: true,
    },
    teams: {
      text: 'Manage Teams',
    },
    scheduler: {
      text: 'Scheduler',
    },
    reports: {
      text: 'Reports',
      active: true
    },
    resource: {
      text: 'Resources',
      active: true
    }  ,
      studenttransfer: {
          text: 'Student Transfer',
          active: true
      }
  };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM