javascript - jade 模板中的脚本标记不使用 Angular 生成结束标记

标签 javascript angularjs pug

我正在阅读 Getting Mean 这本书,但在第 8 章第 2 节遇到了麻烦。出版商的论坛帮不上什么忙。

希望有人能给出一些启示,因为我不知道为什么它不能像书中声称的那样工作。

我认为问题可能与我正在使用的 View 有关。

    doctype html
    html(ng-app='loc8rApp')
      head
        meta(name='viewport', content='width=device-width, initial-scale=1.0')
        title= title
        link(rel='stylesheet', href='/bootstrap/css/amelia.bootstrap.css')
        link(rel='stylesheet', href='/stylesheets/style.css')
      body
       .navbar.navbar-default.navbar-fixed-top
          .container
            .navbar-header
              a.navbar-brand(href='/') Loc8r
              button.navbar-toggle(type='button', data-toggle='collapse', data-target='#navbar-main')
                span.icon-bar
                span.icon-bar
                span.icon-bar
            #navbar-main.navbar-collapse.collapse
              ul.nav.navbar-nav
                li
                  a(href='/about/') About

        .container
          block content

          footer
            .row
              .col-xs-12
                small © Simon Holmes 2014

        script(src='/angular/angular.js')
        script(src='/angular/loc8rApp.js')
        script(src='/javascripts/jquery-1.11.1.min.js')
        script(src='/bootstrap/js/bootstrap.min.js')
        script(src='/javascripts/validation.js')

因为它在我加载页面时生成以下 html:

    <script src="/angular/angular.js"><script src="/angular/loc8rApp.js"></script>
    <script src="/javascripts/jquery-1.11.1.min.js"></script>
    <script src="/bootstrap/js/bootstrap.min.js"></script>
    <script src="/javascripts/validation.js"></script>

这意味着 loc8rApp.js 文件似乎包含在未关闭的脚本标签中。

当我加载页面时,chrome 中的控制台抛出的错误是:

Uncaught Error: [$injector:modulerr] Failed to instantiate module loc8rApp due to:
Error: [$injector:nomod] Module 'loc8rApp' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument. 

以防万一问题是 Angular Controller 文件 (loc8rApp.js),它在这里:

    angular.module('loc8rApp', []);

    var locationListCtrl = function ($scope) {
        $scope.data = {
            locations: [{
              //location data in here...
            }]
        };
    };

    var ratingStars = function() {
      // other code in here...
    };

    angular
        .module('loc8rApp')
        .controller('locationListCtrl', locationListCtrl)
        .filter('formatDistance', formatDistance)
        .directive('ratingStars', ratingStars);

提前感谢任何回复的人! =)

最佳答案

在模板文件中,

正文下方的线(第 9 行)间距不正确。

取而代之的是:

    body
     .navbar.navbar-default.navbar-fixed-top

应该是这样的:

    body
      .navbar.navbar-default.navbar-fixed-top

这个错误出现在我克隆的 github chapter-08 分支存储库中,并用于处理本章中教授的代码。我现在已经提交了一个拉取请求来解决这个问题,希望它不会影响太多其他人。

PR 可以在这里找到:https://github.com/simonholmes/getting-MEAN/pulls

关于javascript - jade 模板中的脚本标记不使用 Angular 生成结束标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40102916/

相关文章:

javascript - JS 函数的定义方式会影响它的 "performance"吗?

javascript - Symfony2 Ajax 根本不启动

javascript - Bootstrap 模式无法在 ng-include 内工作

angularjs - <select> 元素的第一个选择在 IE 中不起作用

angularjs - Angular Material 输入验证错误消息

javascript - 类型错误 : Cannot read property 'then' of undefined on Promise in Express route

javascript - 使用python请求登录jsp登录页面

javascript - AngularJS 动态添加输入字段并保持对每个字段的引用

html - 如何制作服务器端 HTML 模板?

node.js - nodejs jade从配置加载链接