Javascript $location.path()和$routeProvider不工作
我无法通过$routeProvider和$location.path从log.html重定向到index.html,并且在添加log.html的控制器时出现错误,运行了1000次,有人可以告诉我这里有什么问题:/ 我的应用程序结构Javascript $location.path()和$routeProvider不工作,javascript,angularjs,node.js,sockets,Javascript,Angularjs,Node.js,Sockets,我无法通过$routeProvider和$location.path从log.html重定向到index.html,并且在添加log.html的控制器时出现错误,运行了1000次,有人可以告诉我这里有什么问题:/ 我的应用程序结构 node_modules view -log.html -index.html server.js package.json 文件log.html作为客户端 <script type="application/javascript"> soc
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>
我能做的就是宣布一个主要州
state('main', {
url : '/',
templateUrl : '/main.html'
}
你应该这样做重定向
$location.path("/");
到底是什么错误?你在控制台里看到了什么?它是“好的宝贝!!”循环一千次,尽管url是:站点仍然是log.htmlIt,但处理程序函数似乎被多次调用,将log.html及其脚本反复发送到视图。奇怪,我不知道为什么会这样。可能错误在别处。您确定语法正确吗?你不是在用快车吗?我检查了我的一个工作文件,得到了:app=express;服务器=需要“http”。createServerapp;io=需要'socket.io'。listenserver;server.listenport
$location.path("/");