javascript - 請(qǐng)教AngularJS的ngRoute問題:為何這段程序無法執(zhí)行?問題出在哪?
問題描述
/** index.html **/<!DOCTYPE html><html ng-app='exampleApp'><head> <title>Products</title> <script src='http://www.leifengta.com.cn/wenda/angular.js'></script> <script src='http://www.leifengta.com.cn/wenda/angular-route.js'></script> <script src='http://www.leifengta.com.cn/wenda/products.js'></script> <link href='http://www.leifengta.com.cn/wenda/bootstrap.css' rel='stylesheet' /> <link href='http://www.leifengta.com.cn/wenda/bootstrap-theme.css' rel='stylesheet' /></head><body ng-controller='defaultCtrl'><p class='panel panel-primary'> <h3 class='panel-heading'>Products</h3> <p ng-view></p></p></body></html>
/** products.js **/angular.module('exampleApp', ['ngRoute']) .config(function ($routeProvider) { $routeProvider.when('/list', {templateUrl: '/tableView.html'}); $routeProvider.when('/edit', {templateUrl: '/editorView.html'}); $routeProvider.when('/create', {templateUrl: '/editorView.html'}); $routeProvider.otherwise({templateUrl: '/tableView.html'});}) .controller('defaultCtrl', function ($scope, $location) { $scope.currentProduct = null; $scope.listProducts = function () {$scope.products = [ {id: 0, name: 'Dummy1', category: 'Test', price: 1.25}, {id: 1, name: 'Dummy2', category: 'Test', price: 2.45}, {id: 2, name: 'Dummy3', category: 'Test', price: 4.25}]; }; $scope.deleteProduct = function (product) {$scope.products.splice($scope.products.indexOf(product), 1); }; $scope.createProduct = function (product) {$scope.products.push(product);$location.path('/list'); }; $scope.updateProduct = function (product) {for (var i = 0; i < $scope.products.length; i++) { if ($scope.products[i].id === product.id) {$scope.products[i] = product;break; }}$location.path('/list'); }; $scope.editOrCreateProduct = function (product) {$scope.currentProduct = product ? angular.copy(product) : {};$location.path('/edit'); }; $scope.saveEdit = function (product) {if (angular.isDefined(product.id)) { $scope.updateProduct(product);} else { $scope.createProduct(product);} }; $scope.cancelEdit = function () {$scope.currentProduct = {};$location.path('/list'); }; $scope.listProducts();});
/** tableView.html(略) **/
/** editorView.html(略) **/
程序無法執(zhí)行(如圖):
問題解答
回答1:$routeProvider定義路徑時(shí),不應(yīng)該以'/'開頭
用stateProvider
相關(guān)文章:
1. docker 17.03 怎么配置 registry mirror ?2. 前端 - @media query 使用出現(xiàn)的問題?3. docker 下面創(chuàng)建的IMAGE 他們的 ID 一樣?這個(gè)是怎么回事????4. node.js - mongodb查找子對(duì)象的名稱為某個(gè)值的對(duì)象的方法5. 運(yùn)行python程序時(shí)出現(xiàn)“應(yīng)用程序發(fā)生異常”的內(nèi)存錯(cuò)誤?6. html5 - datatables 加載不出來數(shù)據(jù)。7. 測(cè)試自動(dòng)化html元素選擇器元素ID或DataAttribute [關(guān)閉]8. javascript - QQ第三方登錄的問題9. 利用IPMI遠(yuǎn)程安裝centos報(bào)錯(cuò)!10. spring-mvc - spring-session-redis HttpSessionListener失效

網(wǎng)公網(wǎng)安備