2016-07-30 7 views
0

角度のあるビューを表示しようとしています。コンソールはエラーまたは警告をスローしません。ビューを表示していませんAngularJS

同様に、ビューは表示されません。 私は何が間違っていますか?

index.htmlを

<!DOCTYPE html> 
<html lang="en" ng-app="app"> 
<head></head> 
    <body> 

     <ng-view></ng-view> 

     <!-- build:js bower/vendor --> 
     <script type="text/javascript" src="../bower_components/angular/angular.min.js"></script> 
     <script src="../bower_components/angular-route/angular-route.min.js"></script> 
     <!-- endbuild --> 

     <script src="./routes.js"></script> 

     <!-- build:app scripts/js || CUSTOMER --> 
     <script src="./components/customer/customerService.js"></script> 
     <script src="./components/customer/customerController.js"></script> 
     <!-- endbuild--> 

    </body> 
</html> 

routes.js

var _templateBase = './components'; 

angular.module('app', [ 
    'ngRoute' 
]) 
.config(['$routeProvider', function ($routeProvider) { 
     $routeProvider 
     .when('/', { 
      templateUrl: _templateBase + '/customer/customer.html' , 
      controller: 'customerController', 
      controllerAs: '_ctrl' 
     }) 
     .otherwise({ 
      redirectTo: '/' 
     }); 
    } 
]); 

costomerService.js

angular.module('app', []) 
     .factory('customerService', function() { 

     }); 

costomerController.js

angular.module('app',[]) 
    .controller('customerController', ['$scope', function($scope, customerService) { 
     // 
    }]); 

それは間違っていますか?ビューが表示されないため?私は古くから使われているマートドッドを使っています。そこに多くのチュートリアルがあります。

ありがとうございます。それは新しいアプリを作成する原因となっているので、

angular.module('app', [ 
    'ngRoute' 
]) 

はあなたの他のangular.module()定義の二番目のパラメータを削除します。あなたは二番目のパラメータ(注入する依存関係の配列)が含まれているため

答えて

1

これはあなたのアプリケーションを作成します毎回。

angular.module('app') <-- no second parameter tells it to use the existing 'app' module 
    .factory('customerService', function() { 

    }); 

angular.module('app') <-- no second parameter tells it to use the existing 'app' module 
    .controller('customerController', ['$scope', 'customerService', function($scope, customerService) { 
     // 
    }]); 

配列の要素は、あなたの関数パラメータに正確に一致する必要があるため、私はあなたのコントローラの定義上の射出アレイにcustomerServiceを追加しました。 また、経路定義で行ったようにcontrollerAs構文を使用している場合は、コントローラに$scopeを注入したくないかもしれません。

+0

素晴らしいです。ありがとうございました。あなたは素晴らしいです。 –

関連する問題