前端 - ng-view不能加載進模板
問題描述
在學習angularjs教程,ng-view 沒有加載進模板,但是按照官方的寫法又能加載進模板,我自己的寫法不行!我的寫法與官方的有啥區(qū)別,為啥不能加載進模板呢?下面是我的項目目錄結構
app.js
’use strict’;/* App Module */angular.module(’phonecatApp’,[’ngRoute’]).config([’$routeProvider’,function($routeProvider) { $routeProvider .when(’/phones’,{ templateUrl:’partials/phone-list.html’,controller:’PhoneListCtrl’}) .when(’/phones/:phoneId’, { templateUrl:’partials/phone-detail.html’,controller:’PhoneDetailCtrl’}) .otherwise({redirectTo: ’/phones’});}]);
controller.js
angular.module(’phonecatApp’,[]).controller(’PhoneListCtrl’,[’$scope’,’$http’, function($scope, $http) { $http.get(’phones/phones.json’) .success(function(data) {$scope.phones = data.splice(0,5); }); $scope.orderProp = ’age’;}]).controller(’PhoneDetailCtrl’,[’$scope’,’$routeParams’,function($scope,$routeParams) { $scope.phoneId = $routeParams.phoneId;}]);官方教程上的寫法
app.js
var phonecatApp = angular.module(’phonecatApp’, [ ’ngRoute’, ’phonecatControllers’]);phonecatApp.config([’$routeProvider’, function($routeProvider) { $routeProvider. when(’/phones’, {templateUrl: ’partials/phone-list.html’,controller: ’PhoneListCtrl’ }). when(’/phones/:phoneId’, {templateUrl: ’partials/phone-detail.html’,controller: ’PhoneDetailCtrl’ }). otherwise({redirectTo: ’/phones’ }); }]);
controller.js
var phonecatControllers = angular.module(’phonecatControllers’, []);phonecatControllers.controller(’PhoneListCtrl’, [’$scope’, ’$http’, function($scope, $http) { $http.get(’phones/phones.json’).success(function(data) { $scope.phones = data; }); $scope.orderProp = ’age’; }]);phonecatControllers.controller(’PhoneDetailCtrl’, [’$scope’, ’$routeParams’, function($scope, $routeParams) { $scope.phoneId = $routeParams.phoneId; }]);
問題解答
回答1:angular.module(’phonecatApp’,[])使用已存在的模塊的時候不要加后面的依賴了。。。angular.module(’phonecatApp’)。。。這樣就ok了!你上面那樣類似重新定義了一個名為phonecatApp的模塊,依賴是空[]。
回答2:module 重定義了,controller 里換個名字,app 中依賴它
相關文章:
1. 關docker hub上有些鏡像的tag被標記““This image has vulnerabilities””2. nignx - docker內nginx 80端口被占用3. docker容器呢SSH為什么連不通呢?4. css - chrome瀏覽器input記錄上次cookie信息后,有個黃色背景~如何去除!5. debian - docker依賴的aufs-tools源碼哪里可以找到???6. docker網(wǎng)絡端口映射,沒有方便點的操作方法么?7. android clickablespan獲取選中內容8. javascript - 移動端css動畫播放狀態(tài)暫停在ios不起作用 animation-play-state9. docker images顯示的鏡像過多,狗眼被亮瞎了,怎么辦?10. docker綁定了nginx端口 外部訪問不到
