【问题标题】:angular ui-router can't find script template in headangular ui-router 在头部找不到脚本模板
【发布时间】:2015-08-11 13:50:05
【问题描述】:

我正在尝试将内联模板注入我的身体,但我得到了一个

GET http://localhost:3000/home.html 404 (Not Found) 控制台出错。

我已将脚本包含在头部中。

!!!
%html
  %head
    %title Movieseat

    %script{:id => "/home.html", :type => "text/ng-template"}
      .page-header
        %h1 Flapper News

  %body{"ng-app" => "movieseat"}

    %div{"ui-view" => ""}
    %a{"ui-sref" => "state1"} State 1
    %a{"ui-sref" => "state2"} State 2
    %a{"ui-sref" => "home"} home

这是路由模块,

angular.module('movieseat').config([

  '$urlRouterProvider', '$stateProvider', function($urlRouterProvider, $stateProvider) {
    $urlRouterProvider.otherwise('/home');

    $stateProvider

    .state('home', {
      url: '/home',
      templateUrl: '/home.html',
      controller: 'searchCtrl'
    })

    .state('state1', {
      url: '/state1',
      templateUrl: 'assets/angular-app/templates/state1.html'
    })

    .state('state2', {
      url: "/state2",
      templateUrl: "assets/angular-app/templates/state2.html"
    })
  }

]);

script标签上的html>erb转换有问题吗?

【问题讨论】:

    标签: angularjs angular-ui-router


    【解决方案1】:

    问题是您的 ng-app 位于 body 上,因此 head 中的脚本标签超出了您的主要角度模块的范围。

    如果 $templateCache 或脚本标签中不存在 templateUrl(也存在于 $templateCache 中),则向服务器发出请求以检索它。

    由于您的标签超出了应用程序的范围,因此无法找到它,因此会生成服务器请求。

    可能的解决方案:

    将脚本标签移动到正文中或将ng-app属性移动到<html>标签

    【讨论】:

      【解决方案2】:

      在仔细阅读之后,我发现我需要将脚本放在正文中,而不是放在头中。将其放入页脚后,其余脚本即可使用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-04-12
        • 2017-06-24
        • 1970-01-01
        相关资源
        最近更新 更多