0
我无法通过$ routeProvider和$ location.path()从log.html重定向到index.html,并且从添加(控制器log.html运行a一千次),有人可以让我知道什么是错在这里:/
我的应用程序结构
node_modules
view
-log.html
-index.html
server.js
package.json
文件log.html作为客户端
<script type="application/javascript">
socket = io.connect('http://localhost:1337/');
angular.module('Log',['ngRoute'])
.config(['$routeProvider','$locationProvider', function($routeProvider,$locationProvider){
$locationProvider.html5Mode(true).hashPrefix('!');
$routeProvider
.when('/main', {
templateUrl: '/view/index.html'
});
}])
.controller('LogCtrl',['$scope','$location', function($scope,$location){
console.log('ok baby !!');
$scope.addUser = function(){
socket.emit('init',$scope.user);
$location.path("/main");
};
}]);
</script>
<body >
<div class=" main" ng-controller = "LogCtrl" style = "width: 300px; ">
<fieldset>
<form ng-submit = "addUser()">
<h2 >Hello!!</h2>
<input ng-model = "user" required style = "width: 200px; " placeholder = "Nhập tên của bạn" >
<input type = "submit" value = "OK">
<view></view>
</form>
</fieldset>
</div>
和我的服务器端
var app = require('http').createServer(handler)
, io = require('socket.io').listen(app)
, fs = require('fs');
app.listen(1337);
function handler (req, res) {
fs.readFile('./view/log.html',
function (err, data) {
if (err) {
res.writeHead(500,{'Content-Type': 'text/html'});
return res.end('Error loading log.html');
}
res.writeHead(200);
res.end(data);
});
}
究竟什么是错误?你在控制台中得到什么? –
这是'好宝贝!!'循环一千次 –
,虽然网址是:http:// localhost:1337/main该网站仍然是log.html –