0
Я не могу перенаправить на index.html из log.html через $ routeProvider и $ location.path() и получил ошибки от добавления (контроллер log.html запускает тысячу раз), может кто-то дайте мне знать, что неправильно здесь:/
Моя структура приложения
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);
});
}
Что ошибка именно? Что вы получаете в консоли? –
Это нормально, детка! петля тысячу раз –
, и хотя URL-адрес: http: // localhost: 1337/main, сайт по-прежнему является log.html –