這是我的代碼:angular.js - 讓路由問題工作
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<style>
</style>
</head>
<body ng-app="myApp" >
<div data-role="page" id="pageone">
<div data-role="header">
<h1>WELCOME!</h1>
</div>
<div ng-view></div>
<div data-role="footer">
<h1>© 2015 - HSKA</h1>
</div>
</div>
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script>
'use strict';
var app = angular.module('myApp', ['ngRoute']);
app.config(function($routeProvider) {
$routeProvider
.when('/', {
templateUrl : 'views/home.html',
controller : 'HomeController'
})
.when('/abc', {
templateUrl : 'views/abc.html',
controller : 'abcController'
})
.when('/def', {
templateUrl : 'views/def.html',
controller : 'defController'
})
.when('/efg', {
templateUrl : 'views/efg.html',
controller : 'efgsController'
});
});
app.controller('HomeController', function($scope, $http, $location) {
$http.get('http://localhost/webapp/dbconnect.php').
success(function(data) {
$scope.users = data;
}).error(function(data) {
console.log("error");
});
});
app.controller('abcController', function($scope) {
$scope.info = 'abcController';
});
app.controller('defController', function($scope) {
$scope.info = 'defController';
});
app.controller('efgsController', function($scope) {
$scope.info = 'efgsController';
});
</script>
</body>
</html>
這是多麼即G。在efg.html看起來:
<div data-role="main" class="ui-content" ng-controller="efgsController">
<h1>VG</h1>
<p>{{ info }}</p>
</div>
不過,我得到以下錯誤:
Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.3.14/$injector/modulerr?p0=myApp&p1=Error%3A%…gleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.14%2Fangular.min.js%3A17%3A381)
我究竟在做什麼錯?我是否使用過時的方式來執行此操作?
幫助和提示將不勝感激!
呃...什麼是noob錯誤。我認爲這一切都在一個文件中......謝謝! – user3629892