繁体   English   中英

角度模板路由不起作用

[英]Angular template routing doesn't work

当我查看我的 angular 项目时,我想在我的主 index.html 中加载一个模板 html,但我总是得到一个空屏幕。

<!DOCTYPE html>
<html lang="nl" ng-app="store">
<head>
    <meta charset="UTF-8">
    <title>NMDAD-II Web App</title>
    <link rel="stylesheet" href="css/main.css">
    <link rel="stylesheet" href="css/style.css">
</head>
<body class="bg-darkRed" ng-controller="StoreController as store">

<div ng-view></div>


<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.28//angular-route.min.js"></script>
<script src="vendor/angular/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="js/main.js"></script>
<script src="app/app.js"></script>
<script type="text/javascript">

    angular.module("store", ["ngRoute"])
            .config(function($routeProvider){
                $routeProvider
                        .when('/', {
                            templateUrl: 'app/home/home.view.html'
                        })
                        .otherwise({
                            redirectTo: '/'
                        });
            });

</script>


<script id="__bs_script__">//<![CDATA[
document.write("<script async src='http://HOST:3000/browser-sync/browser-sync-client.2.11.2.js'><\/script>".replace("HOST", location.hostname));
//]]></script>
</body>
</html>

我也试过用浏览器同步加载它,但它仍然是一样的。 我想在我的 index.html 中加载 home.view.html。 我试图在 app.js 中编写 javascript 但仍然没有用。

编辑:这是我的 app.js。 我的 main.js 只包含一些 jquery

function () {


    'use strict';

    // Module declarations
    angular.module('store', [
        // Angular Module Dependencies
        // ---------------------------
        'ngAnimate',
        'ngMaterial',
        'ngMessages',
        'ngResource',


        // Third-party Module Dependencies
        // -------------------------------
        'ui.router', // Angular UI Router: https://github.com/angular-ui/ui-router/wiki

        // Custom Module Dependencies
        // --------------------------
        'store.home',
        'store.services'
    ]);
    angular.module('store.home', []);
    angular.module('store.services', []);

    // Make wrapper services and remove globals for Third-party Libraries
    angular.module('store')
        .run(Run);


    function Run(
        $_,
        $faker
    ) {}



    var app = angular.module('store',[]);

    app.controller('StoreController', function(){
        this.products = gems;
    });

  var gems = [
      {
          title: "Islay Blended Malt",
          description: "The Isle of Islay is known for its peaty whiskies. For there is a great abundance of peat on the island, and because electricity reached Islay so late, peated was relied upon as a staple source of fuel. But there is so much than just peat to be found.",
          price: "103.45",
          canPurchase: true

      },

      {
          title: "Springbank 10 Year old",
          description: "Blended from a mixture of bourbon and sherry casks, the light colour of this malt belies the richness of its character.",
          price: "36.25",
          canPurchase: true

      },

      {
          title: "Hazelburn 10 Year old",
          description: "First released in 2014, this is the first bottling of Hazelburn at 10 years of age. Hazelburn is Springbank's triple-distilled, unpeated single malt.",
          price: "37.75",
          canPurchase: true

      }
  ]

})();

我看到的问题是您在加载 angular 之前加载了 angular-route。

尝试将这两行切换为:

<script src="vendor/angular/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.28//angular-route.min.js"></script>

我收到这个错误ReferenceError: angular is not defined当我加载脚本时,你是如何加载它们的。

暂无
暂无

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

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