javascript - Angular UI-Router 无法加载我没有要求的模板

标签 javascript angularjs angular-ui angular-ui-bootstrap

Plunker Code Showing Issue Described Below

http://plnkr.co/edit/Bz3Qhf1eDuFrnKI0qnUo?p=preview

我正在使用 AngularUI 套件的两个组件,UI-Router 和 UI-Bootstrap。 UI-Router 负责在用户点击我的顶部导航栏链接时加载模板。

只有“UI Widget Templates”(AngularUI-Bootstrap 和 Alert)下的前两个链接处于事件状态

enter image description here

UI-Bootstrap 负责在模板中制作漂亮的小部件。 我似乎已正确配置 UI-Router,因为我正在加载正确的模板,并且这些模板可以访问正确的 Controller 。我遇到的问题是我的 UI-Bootstrap 组件无法加载并生成奇怪的错误,这似乎表明它们正在以某种方式尝试自己加载模板??? 我在我的实现中有什么错误处理导致 Bootstrap-UI 指令无法加载?

警报下 zipper 接的 HTML 模板

<tabset>
  <tab heading="Static title">Static content</tab>
  <tab ng-repeat="tab in tabs" heading="{{tab.title}}" active="tab.active"           disabled="tab.disabled">
    {{tab.content}}
  </tab>
  <tab select="alertMe()">
  <tab-heading>
    <i class="icon-bell"></i> Select me for alert!
  </tab-heading>
  I've got an HTML heading, and a select callback. Pretty cool!
  </tab>
 </tabset>

{{tabs}}

加载警报模板时来自控制台的错误消息

enter image description here

Angular 优势

angular.module("uiRouterExample", [
'ui.router',
'ui.bootstrap']).config(function ($stateProvider, $urlRouterProvider) {
    $stateProvider
        .state('home', {
            url: '/home',
            templateUrl: 'templates/home.html',
            controller: 'BSCtrl'
        })
        .state('angularBS', {
            url: '/angularBS',
            templateUrl: 'templates/angularBS.html',
            controller: 'BSCtrl'
        })
        .state('alert', {
            url: '/alert',
            templateUrl: 'templates/alert.html',
            controller: 'BSCtrl'
        })
    ;
})
.controller('BSCtrl', function ($scope) {

    $scope.tabs = [
      { title:"Accordion", content:"Dynamic content 1" },
      { title:"Alert", content:"Dynamic content 2"},
      {title:"Buttons", content:"More Dynamic Content"}
    ];

    $scope.test="Hello World";

    $scope.alerts = [
      { type: 'error', msg: 'Oh snap! Change a few things up and try submitting again.' }, 
      { type: 'success', msg: 'Well done! You successfully read this important alert message.' }
    ];

    $scope.addAlert = function() {
      $scope.alerts.push({msg: "Another alert!"});
    };

    $scope.closeAlert = function(index) {
      $scope.alerts.splice(index, 1);
    };

});

最佳答案

UI-Bootstrap 依赖于 ui-bootstrap-[version].js 文件中不存在的模板。描述了构建文件配置选项 here .相关片段:

Files with the -tpls in their name have bootstrap-specific templates bundled with directives. For people who want to take all the directives and don't need to customize anything the solution is to grab a file named ui-bootstrap-tpls-[version].min.js. If, on the other hand default templates are not what you need you could take ui-bootstrap-[version].min.js and provide your own templates...

在 plunkr 中,您使用的是 ui-bootstrap-0.7.0.js,而不是 ui-bootstrap-tpls-0.7.0.js。前者没有与模板捆绑在一起,但仍然在指令的 templateUrls 下硬编码了对它们的引用,例如:

.directive('alert', function() {
  return {
    ...
    templateUrl:'template/alert/alert.html',
    ...
  };
}])

编辑,包括@inolasco 的回答:

如果你使用 ui-bootstrap-tpls.js 仍然有这个问题,可能是你需要添加

'ui.bootstrap.tpls'

到你的模块。

关于javascript - Angular UI-Router 无法加载我没有要求的模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20157008/

相关文章:

javascript - 如何在验证失败时保留输入表单值 Spring MVC

javascript - 我是否需要单独的 View 来创建新数据和加载现有数据?

javascript - 当 Controller 中的 $scope 值更改时,$scope 值不会在 View 中更新

javascript - angular-ui-layout - 调整大小无法在 iframe 中正常工作

angularjs - Angular-ui 引导模式,无需创建新 Controller

javascript - 选择具有特定类的元素的父级

javascript - 在 Node.js 和 Express 中使用角色进行日志记录

angularjs - 为什么我不能在 Firefox 中绑定(bind)到 Angular 模型的输入中输入文本?

javascript - 如何在 Angular ui 路由器上转换到另一个模式后关闭模式

javascript - 为什么在 JS 函数中无法正确创建按钮?