Angularjs 控制台上没有错误,但html没有';t载荷

Angularjs 控制台上没有错误,但html没有';t载荷,angularjs,ng-view,Angularjs,Ng View,我不知道为什么这不起作用。我做错了什么?控制台中没有错误,但main.html和about.html中的html不会加载 当我在html中直接使用controller时,它确实工作得很好,但当我使用上面的代码时,ng视图无法从main.html和about.html文件中获取html app.js angular .module('invoice2', [ 'ngRoute' ]) .config(function ($routeProvider) { $routeP

我不知道为什么这不起作用。我做错了什么?控制台中没有错误,但main.html和about.html中的html不会加载

当我在html中直接使用controller时,它确实工作得很好,但当我使用上面的代码时,ng视图无法从main.html和about.html文件中获取html

app.js

angular
  .module('invoice2', [
    'ngRoute'
  ])
  .config(function ($routeProvider) {
    $routeProvider
      .when('/', {
        templateUrl: 'views/main.html',
        controller: 'MainCtrl'
      })
      .when('/about', {
        templateUrl: 'views/about.html',
        controller: 'InvoiceController'
      })
      .otherwise({
        redirectTo: '/'
      });
  });
关于.js

angular.module('finance2', [])
.factory('currencyConverter', function() {
  var currencies = ['USD', 'EUR', 'CNY'];
  var usdToForeignRates = {
    USD: 1,
    EUR: 0.74,
    CNY: 6.09
  };
  var convert = function (amount, inCurr, outCurr) {
    return amount * usdToForeignRates[outCurr] / usdToForeignRates[inCurr];
  };

  return {
    currencies: currencies,
    convert: convert
  };
});

angular.module('invoice2', ['finance2'])
.controller('InvoiceController', ['currencyConverter', function(currencyConverter) {
  this.qty = 1;
  this.cost = 2;
  this.inCurr = 'EUR';
  this.currencies = currencyConverter.currencies;

  this.total = function total(outCurr) {
    return currencyConverter.convert(this.qty * this.cost, this.inCurr, outCurr);
  };
  this.pay = function pay() {
    window.alert("Thanks!");
  };
}]);
index.html

<body ng-app="invoice2">        
    <div class="container">
        <div ng-view=""></div>
    </div>
</body>

不能多次定义模块

你在干什么

angular
  .module('invoice2', [
    'ngRoute'
  ])
后来

angular.module('invoice2', ['finance2'])
它覆盖了第一个。取而代之的是,创建一个依赖项数组,稍后再获取模块

// define it once
angular.module('invoice2', ['ngRoute', 'finance2'])

// and get that instance later
var app = angular.module('invoice2');

刚意识到你的答案和我的一样,但是,你比我领先了好长一段时间。删除我的答案。真遗憾。。。现在我明白我做错了什么。非常感谢@nikhil和@Patrick!