gpt4 book ai didi

单击按钮导航到另一个页面的 AngularJs 代码

转载 作者:行者123 更新时间:2023-12-01 08:07:14 25 4
gpt4 key购买 nike

AngularJs 代码在按钮单击事件中导航到另一个页面。我已捕获按钮单击事件但无法导航到另一个页面。以下是我的代码:HTML 文件:

<!DOCTYPE html>

<html>

<head>

<script src="js/angular.min.js"></script>

<script src="js/app/home.js"></script>

</head>

<body ng-app="myapp">

<div ng-controller="TestCtrl">

<button ng-click="clicked()">Click me!</button>

</body>

</html>

javascript 文件是:

var VLogin = angular.module('myapp',[]);

VLogin.controller('TestCtrl', ['$scope',function($scope) {

$scope.clicked = function(){

$location.path('/test.html');
}

}]);

最佳答案

尝试如下所示...

在 html 中,

 <button ng-click="clicked()">Click</button>

在 JS 中,

 $scope.clicked = function(){
window.location = "#/test.html";
}

希望对你有帮助...

关于单击按钮导航到另一个页面的 AngularJs 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26098223/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com