Angular js路由不能正常工作,甚至试过CDN

时间:2016-12-11 08:41:27

标签: angularjs

我可以看到网址中的更改,但该网页中的内容在ng-view中无法显示,请提供帮助。以下是代码文件。

Angular script

.button-hover {
    font-family: arial black;
    font-size: 100px;
    color: #000;
    -webkit-transition: opacity 1s ease-in-out;
    -moz-transition: opacity 1s ease-in-out;
    -ms-transition: opacity 1s ease-in-out;
    -o-transition: opacity 1s ease-in-out;
    transition: opacity 1s ease-in-out;
    opacity: 1;
}

.button-hover:hover {
    opacity: 0.5;
}

Html代码 这是主要的用户界面。

<div class="container">
    <a href="#" class="button-hover">HOVER ME</a>
</div>

Home.html中

<script>
var app = angular
                 .module("myapp", ["ngRoute"])
                 .config(function ($routeProvider) {
                          $routeProvider
                          .when("/Home", {
                              templateUrl: "Home.html",       
                          })
                          .when("/ThankYou", {
                              templateUrl: "ThankYou.html",                       
                          })
                      })                     
</script>

enter image description here

1 个答案:

答案 0 :(得分:0)

var app = angular.module("Demo", ['ngRoute']);
app.config(function($routeProvider) {
  $routeProvider
    .when('/Home', {
      templateUrl: 'Home.html',
      controller: 'FirstController'
    })
  .when('/ThankYou', {
    templateUrl: 'ThankYou.html',
    controller: 'SecondController'
  })
});
app.controller('FirstController', function($scope) {

});
app.controller('SecondController', function($scope) {

});

<强> DEMO