Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript $location.path使用Angularjs在单击按钮时未加载html文件_Javascript_Html_Angularjs_Node.js - Fatal编程技术网

Javascript $location.path使用Angularjs在单击按钮时未加载html文件

Javascript $location.path使用Angularjs在单击按钮时未加载html文件,javascript,html,angularjs,node.js,Javascript,Html,Angularjs,Node.js,我有一个html my.html,其中包含一个按钮,我想在其上单击该按钮将用户发送到about.html,现在我面临的问题是按钮单击,我将进入控制器,但当我调用该方法时 $location.path("\about") 什么都不会发生,只会显示我的当前页面,但不会加载我的about.html 我尝试使用$window.open('/about.html','u self')而且它工作得非常好,但我不知道为什么$location.path对我不起作用 我也在使用。这会引起什么问题吗 my.htm

我有一个html my.html,其中包含一个按钮,我想在其上单击该按钮将用户发送到about.html,现在我面临的问题是按钮单击,我将进入控制器,但当我调用该方法时

$location.path("\about")
什么都不会发生,只会显示我的当前页面,但不会加载我的about.html

我尝试使用
$window.open('/about.html','u self')
而且它工作得非常好,但我不知道为什么
$location.path
对我不起作用

我也在使用
。这会引起什么问题吗

my.html代码


登录
用户名:
密码:
登录
controller.js

var-app=angular.module('myApp',['ngRoute']);
app.config(函数($locationProvider,$routeProvider){
console.log(“你好”);
$locationProvider.html5Mode(true);
$routeProvider
.when(“/关于”{
templateUrl:'about.html'
})
.否则({
templateUrl:'about.html'
});
});
应用程序控制器('loginCtrl',函数($scope,$location){
console.log(“hello1”)
$scope.submit=function(){
var uname=$scope.username;
var pwd=$scope.password;
控制台日志(“内部控制器”);
$location.path('/about');
};
});
你们谁能告诉我如何用AngularJS做这个

关于.js

app.js

var express=require('express');
var bodyParser=require('body-parser');
var http=require('http');
var https=require('https');
var fs=需要('fs');
var-app=express();
app.use(express.static(uu dirname+/public));
use(bodyParser.json());
app.use(bodyParser.urlencoded({
扩展:正确
}))
app.get('/',函数(req,res){
控制台日志(“全局”);
res.sendFile(uu dirname+'/public/my.html');
});
var util=require('util');
var port=process.env.port | | 8080;
http.createServer(app.listen)(8080);
我的目录结构定义如下,我正在用app.js运行nodejs服务器

project/
         my.html
         about.html
         app.js
         js/
           controller.js 
           angular.js
           angular-route.js
更改浏览器URL时不会导致重新加载整个页面。要在更改URL后重新加载页面,请使用较低级别的API$window.location.href

$window.location.href = '/views/Dummy.html';
什么都没有发生只有我的当前页面出现,但我的about.html 不会加载

嗨!我是新来的!但也许我能帮你:)


如果目标路径与当前路径相同,请小心,
$location.path
不会重新加载页面。我建议您使用as
$route.reload()
重新加载具有相同路径的页面。

您需要添加
ng视图

$route服务通常与ngView指令和$routeParams服务一起使用

所有视图都将呈现到此节点中,因此您应该将登录视图移动到不同的
.html
文件中(在我的示例中为
home.html


工作示例:

控制台中是否有错误?您是否尝试删除
base
标记?没有错误,我可以通过按钮单击正确地转到控制器,当我点击按钮时,我的url将更改为,但我的about.html确实被加载。是的,我尝试删除base标记,现在仍然对我有效。是否$location是“未定义”的?尝试将$location服务注入控制器:app.controller('loginCtrl',[“$scop”,“$location”,function($scope,$location){…}])没有未定义的位置,因为当我尝试打印位置时,它正在打印对象,其中$$absUrl为“”正如我在帖子中所说,我使用了window.open和allowwindow方法,对我来说效果非常好,但我不知道为什么$location.path不能给我期望的结果。无论如何,谢谢。$timeout(函数(){$location.path('/about');},0);但是我在每一个教程中都看到简单的$location.path()对他们很好,thye don;那么我如何才能将主布局(index.html)注入到不同的html页面中呢。查看plunkr中的文件列表(我更新了链接)。index.html将只保存布局,其他
html
s文件将只包含部分视图(例如,没有
html
body
等标记)。只需告诉我一件事,您在哪里指定登录页(my.html)?在
home.html
中。你不能在plunkr中看到它吗?对不起,我的最后一个问题很糟糕,我得到错误$animate.enter(…)。done不是一个函数??