AngularJS - 没有错误,但没有视图
我正在做一个angularJS和PHP的项目。
我做了一些编辑,但现在它不工作... 问题是,我没有在控制台和角度工作(我可以得到它的版本)的错误,但我的意见不显示...
你能帮助理解为什么吗?
之前,我渐渐的ServiceProvider错误,但我不知道我是否修复它,因为没有我坚持这个问题,我真的不知道为什么...AngularJS - 没有错误,但没有视图
这里是我的app.js
'use strict';
var app = angular.module('MyApp', ['ngRoute']);
app.factory('services', ['$http', function($http) {
var serviceBase = '/services/';
var obj = {};
obj.getConseils = function(){
return $http.get(serviceBase + 'conseils');
};
obj.getConseil = function(conseilID){
return $http.get(serviceBase + 'conseil?id=' + conseilID);
};
obj.getRoulottes = function(type, marque, dimension, couche, prix){
return $http.get(serviceBase + 'roulottes?type=' + type + '&marque=' + marque + '&dimension=' + dimension + '&couche=' + couche + '&prix=' + prix);
};
obj.getRoulotte = function(roulotteID){
return $http.get(serviceBase + 'roulotte?id=' + roulotteID);
};
return obj;
}]);
/**
* @ngdoc overview
* @name MataneCaravaneGoApp
* @description
* # MataneCaravaneGoApp
*
* Module principal de l'application
*/
app.config(function ($routeProvider) {
$routeProvider
.when('/', {
title: 'Accueil',
templateUrl: 'views/main.html',
controller: 'MainCtrl'
})
.when('/conseils', {
title: 'Nos conseils',
templateUrl: 'views/conseils.html',
controller: 'ConseilsCtrl'
})
.when('/conseil/:conseilID', {
title: 'Conseil',
templateUrl: 'views/conseil.html',
controller: 'ConseilCtrl'
})
.when('/roulottes/type/:type/marque/:marque/dimension/:dimension/couche/:couche/prix/:prix', {
title: 'Roulottes',
templateUrl: 'views/roulottes.html',
controller: 'RoulottesCtrl'
})
.when('/roulottes/type/:type', {
title: 'Roulottes',
templateUrl: 'views/roulottes.html',
controller: 'RoulottesCtrl'
})
.when('/roulotte/:roulotteID', {
title: 'Roulotte',
templateUrl: 'views/roulotte.html',
controller: 'RoulotteCtrl'
})
.otherwise({
redirectTo: '/'
});
});
app.run(['$location', '$rootScope', function($location, $rootScope) {
$rootScope.$on('$routeChangeSuccess', function (event, current) {
$rootScope.title = current.$$route.title;
});
}]);
app.controller('404Ctrl', function ($scope) {
});
app.controller('ConseilsCtrl', function ($scope, services) {
services.getConseils().then(function(data){
$scope.conseils = data.data;
});
});
app.controller('MainCtrl', function ($scope) {
console.log('test');
});
app.controller('RoulotteCtrl', function ($scope) {
});
app.controller('RoulottesCtrl', function ($scope) {
});
我的index.html
<!doctype html>
<html class="no-js" >
<head>
<meta charset="utf-8">
<title>MyApp</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="styles/bootstrap.css" />
<link rel="stylesheet" href="styles/main.css">
</head>
<body ng-app="MyApp">
<!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<header class="header">
<ul class="nav nav-pills pull-right">
<li class="active"><a ng-href="#">Accueil</a></li>
<li><a ng-href="#/conseils">Conseils</a></li>
</ul>
<h1 class="text-muted">MyApp</h1>
</header>
<div ng-view=""></div>
<footer class="footer">
<p><span class="glyphicon glyphicon-heart"></span> from the Yeoman team</p>
</footer>
<!--[if lt IE 9]>
<script src="scripts/es5-shim/es5-shim.js"></script>
<script src="scripts/json3/lib/json3.js"></script>
<![endif]-->
<script src="scripts/jquery/dist/jquery.js"></script>
<script src="scripts/angular/angular.js"></script>
<script src="scripts/bootstrap/dist/js/bootstrap.js"></script>
<script src="scripts/angular-resource/angular-resource.js"></script>
<script src="scripts/angular-sanitize/angular-sanitize.js"></script>
<script src="scripts/angular-animate/angular-animate.js"></script>
<script src="scripts/angular-touch/angular-touch.js"></script>
<script src="scripts/angular-route/angular-route.js"></script>
<script src="scripts/app.js"></script>
</body>
</html>
的问题是你是遍地创建模块。查看文档https://docs.angularjs.org/guide/module中的创建与检索部分。
你有几个拼写错误导致你的问题。我忘了所有我把(一个是在CONSEILS控制器拼写错误)的步骤,但这里是呈现主视图plunkr:
app.controller('ConseilsCtrl', function ($scope, services) {
http://plnkr.co/edit/hkR8Wp?p=preview
链接是不完全正确,但我会留给你的。
我只是编辑我的文件以创建我的角度模块的var,并且在更改后没有任何更改 – 2014-09-25 13:33:32
您能否更新您的代码片段。我会添加一个console.log到你的mainctrl来验证它按预期执行。 – 2014-09-25 13:47:48
编辑,console.log不出现 – 2014-09-25 14:03:10
你期待看到什么? – 2014-09-25 13:17:02
在主页上只有来自一个视图的html,对于协议我显示一个视图,从我的数据库获取数据 – 2014-09-25 13:34:54