[英]ui-router doesn't work from nodejs folder but works on plunker
ui-router is supposed to make an index.html as a header and test.html as a attached view but it doesn't work on my computer for some reason. ui-router应该将index.html作为标题,将test.html作为附加视图,但是由于某些原因,它在我的计算机上不起作用。 Plunker one work great. 插拔一件作品很棒。
index.html is same as on plunker index.html与在plunker上相同
<html ng-app="MyApp">
<head>
<link href="stylesheets/style.css" rel="stylesheet">
</head>
<body>
<h4>
This should be the header
</h4>
<div ui-view></div>
<script data-require="angular.js@*" data-semver="1.3.0-beta.5" src="https://code.angularjs.org/1.3.0-beta.5/angular.js"></script>
<script data-require="ui-router@*" data-semver="0.2.10" src="https://rawgit.com/angular-ui/ui-router/0.2.10/release/angular-ui-router.js"></script>
<script src="app.js"></script>
<script src="controllers/main.js"></script>
</body>
</html>
views/test.html only contains views / test.html仅包含
<div>
this is test.html
</div>
and app.js contains 和app.js包含
angular.module('MyApp', [
'ui.router'
])
.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/');
$stateProvider
.state('main', {
url: '/',
templateUrl: 'vews/test.html',
controller: 'MainCtrl'
});
})
Here is server.js if needed 如果需要,这是server.js
var express = require('express');
var path = require('path');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
var bcrypt = require('bcryptjs');
var app = express();
app.set('port', process.env.PORT || 3000);
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.listen(app.get('port'), function() {
console.log('Express server listening on port ' + app.get('port'));
});
I don't get why ui-router works on plunker, but doesn't at my computer. 我不知道为什么ui-router可以在plunker上工作,但不能在我的计算机上工作。
If the plunker is working, then your local stuff should be as well - and I cannot see any obvious error. 如果the子正在工作,那么您当地的东西也应该是-我看不到任何明显的错误。
But there is a difference. 但是有区别。 Usually in plunker we do not use nesting (sub-folders like views
or controllers
) . 通常在插件中,我们不使用嵌套(子文件夹,例如views
或controllers
) 。 And in your plunker - in comparison with your snippet in the question is: 而在您的朋克中-与您的摘要相比,问题是:
the plunker: 矮人:
$stateProvider
.state('main', {
url: '/',
templateUrl: 'test.html',
controller: 'MainCtrl'
});
the snippet above: 上面的代码段:
$stateProvider
.state('main', {
url: '/',
templateUrl: 'vews/test.html',
controller: 'MainCtrl'
});
And that together seems, that you have a typo in templateUrl where is: 'vews/test.html', instead of views
. 看起来好像您在templateUrl中有一个错字,其中是:'vews / test.html',而不是views
。 Could that be the issue? 这可能是问题吗?
Also, related to the above issues with subfolders, there were some small errors (click F12 in Chrome and check the console)... I fixed them in this fork 另外,与上述与子文件夹有关的问题,还有一些小错误(在Chrome中单击F12并检查控制台)...我在此fork中修复了它们
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.