Angularjs Angular JS中的$location.path不起作用
我知道这个问题已经被问过很多次了,在查看了回复并修改了代码之后,我仍然无法通过按下按钮打开另一页。我刚开始学习Angular JS,有人能帮我吗? url中的地址会更改,但页面不会显示 代码: Index.html main.jsAngularjs Angular JS中的$location.path不起作用,angularjs,Angularjs,我知道这个问题已经被问过很多次了,在查看了回复并修改了代码之后,我仍然无法通过按下按钮打开另一页。我刚开始学习Angular JS,有人能帮我吗? url中的地址会更改,但页面不会显示 代码: Index.html main.js 感谢和问候,请将ngRoute注入您的应用程序,不要伪造添加和引用脚本 在你身上 $location.path('/path'); <- path has to be defined in your app.config ...(ie .when(/path.
感谢和问候,请将ngRoute注入您的应用程序,不要伪造添加和引用脚本 在你身上
$location.path('/path'); <- path has to be defined in your app.config ...(ie .when(/path..)not just path to html file
您的$timeout对于它应该延迟多长时间没有值。您需要在函数之后提供它
$timeout(function () {
$location.path('/views/Dummy.html');
}, 1);
url中的地址会更改,但页面不会显示
更改浏览器URL时不会导致重新加载整个页面。要在更改URL后重新加载页面,请使用较低级别的API$window.location.href
$window.location.href = '/views/Dummy.html';
使用window.location.href查看它不起什么作用。如上所述进行了尝试,但同样的结果是,您的主页中也没有ng视图,因此无法加载该视图。如果没有route和ng视图,您将看不到正在查找的更改。我想打开一个新页面,而不是在同一页面中显示更改。我不能使用$location.path打开新页面吗?打开新页面将退出你的应用程序。Angular用于创建和运行单页应用程序SPA。您可以通过更改视图来实现这一点。我尝试将ngRoute作为依赖项添加到脚本中,但无法跳转到下一页。。
angular
.module('testAngularApp', ['ngRoute'])
.config(function($locationProvider){
$locationProvider.html5Mode(true);
});
$location.path('/path'); <- path has to be defined in your app.config ...(ie .when(/path..)not just path to html file
$timeout(function () {
$location.path('/views/Dummy.html');
}, 1);
$window.location.href = '/views/Dummy.html';