AngularJS路由不会加载视图并报告没有错误

时间:2015-05-27 07:16:37

标签: javascript angularjs

这是结构:

Here is the structure

以下是来源:

/* @flow */
"use strict";
(function () {
  const app = angular.module('Lesson2', ['ngRoute', 'ngAnimate'] );
  app.config(function($routeProvider){
    $routeProvider
      .when('/what', { controller:'FavoCtrl', templateURL:'pages/what.html'})
      .when('/where', { controller:'FavoCtrl', templateURL:'pages/where.html'})
      .otherwise({redirectTo:'/what'});
  });
  app.controller('FavoCtrl', function ($scope) {
    $scope.favouriteThings=[
      {what:'raindrops', by:'on', where:'roses'},
      {what:'whiskers', by:'on', where:'mittens'},
      {what:'Brown paper packages', by:'tied up with', where:'strings'},
      {what:'schnitzel', by:'with', where:'noodles'},
      {what:'Wild geese', by:'that fly with', where:'the moon on their wings'},
      {what:'girls', by:'in', where:'white dresses'},
      {what:'Snowflakes', by:'that stay on', where:'my nose and eyelashes'}
    ];
  })

})();
<!DOCTYPE html>
<html ng-app="Lesson2">
<head lang="en">
    <link rel="stylesheet" type="text/css" href="styles/style.css">
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-route.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-animate.min.js"></script>
    <script src="scripts/app.js"></script>
    <meta charset="UTF-8">
    <title>Lesson 2</title>
</head>
<body>
Hello!
<ng-view></ng-view>
</body>
</html>

两个“what.html”和“where.html”是纯文本,例如This is "where.html"

这里最难的是浏览器不会抛出任何错误,控制台是干净的。视图未加载,我看到的只是“index.html”的“Hello”

2 个答案:

答案 0 :(得分:2)

好像你有错误,在你的配置块中,使用 templateUrl 而不是 templateURL

应该看起来像:

Sub Sample()
    Dim strPath As String
    Dim FSO As Object, oFile As Object
    Dim c As Range
    Dim linefeed_remover
    Dim MyAr

    ActiveWorkbook.Sheets("Sheet1").Activate
    With ActiveSheet
        .Range(.Cells(1, 1), .Cells.SpecialCells(xlCellTypeLastCell)).Select
    End With

    Set oFile = Nothing

    strPath = "C:\Users\Siddharth\Desktop\"
    filesname = "Sample.Txt"

    '~~> Transfer the entire range in an array
    '~~> For faster performcance
    MyAr = Selection.Value

    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set oFile = FSO.CreateTextFile(strPath & filesname)

    For i = LBound(MyAr) To UBound(MyAr)
        '~~> Check if it is the last record so that
        '~~> We do not add the linefeed
        If i = UBound(MyAr) Then
            oFile.Write Application.WorksheetFunction.Clean(MyAr(i, 1))
        Else
            oFile.Write Application.WorksheetFunction.Clean(MyAr(i, 1)) & vbNewLine
        End If
    Next i

    oFile.Close
End Sub

答案 1 :(得分:0)

首先你的路线配置中有一个拼写错误,它是&#34; templateUrl&#34;而不是&#34; templateURL&#34;。

如果这不能解决您的问题,请尝试在index.html中添加控制器

cat