前端 - ng-view不能加載進(jìn)模板
問題描述
在學(xué)習(xí)angularjs教程,ng-view 沒有加載進(jìn)模板,但是按照官方的寫法又能加載進(jìn)模板,我自己的寫法不行!我的寫法與官方的有啥區(qū)別,為啥不能加載進(jìn)模板呢?下面是我的項目目錄結(jié)構(gòu)
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 中依賴它
相關(guān)文章:
1. docker - 如何修改運行中容器的配置2. dockerfile - [docker build image失敗- npm install]4. docker綁定了nginx端口 外部訪問不到5. 為什么我ping不通我的docker容器呢???6. angular.js - angular內(nèi)容過長展開收起效果7. nignx - docker內(nèi)nginx 80端口被占用8. docker不顯示端口映射呢?9. docker api 開發(fā)的端口怎么獲???10.排行榜docker - 如何修改運行中容器的配置 1. 在windows下安裝docker Toolbox 啟動Docker Quickstart Terminal 失敗! 2. dockerfile - [docker build image失敗- npm install] 3. 為什么我ping不通我的docker容器呢??? 4. nignx - docker內(nèi)nginx 80端口被占用 5. angular.js - angular內(nèi)容過長展開收起效果 6. docker綁定了nginx端口 外部訪問不到 7. docker不顯示端口映射呢? 8. 9. docker網(wǎng)絡(luò)端口映射,沒有方便點的操作方法么? 10. docker - 各位電腦上有多少個容器?。咳萜饕欢?,自己都搞混了,咋辦呢? 熱門標(biāo)簽