gpt4 book ai didi

javascript - angularjs:ng-click 不工作,适用于

转载 作者:行者123 更新时间:2023-11-30 08:49:34 25 4
gpt4 key购买 nike

这是Javascript

    function gotoUrl($scope, $location, $http, $window) {
$scope.setRoute = function (route) {
$location.path(route);
};

我的代码是

      <ul class="nav navbar-nav navbar">
<li><a href="#" data-ng-click="setRoute('summary')"><span
class="icon-bar-chart"></span> Summary</a></li>
<li><a href="#
" data-ng-click="setRoute('transactions')"><span
class="icon-reorder"></span>
Transactions</a></li>
<li><a href="#" data-ng-click="setRoute('budgets')"><span
class="icon-calendar"></span>
Budgets</a></li>
</ul>

路由配置为

app.config(function ($routeProvider) {
$routeProvider
.when('/summary', {templateUrl: '../static/partials/summary.html', controller: 'SummaryController'})
.when('/transactions', { templateUrl: '../static/partials/listTransaction.html', controller: 'TransactionsManagerController'})
.when('/profile', {templateUrl: '../static/partials/profile.html', controller: 'ProfileController'})
.when('/new', {templateUrl: '../static/partials/addTransaction.html', controller: 'TransactionAddController'})
.when('/budgets', {templateUrl: '../static/partials/budgets.html'})
.otherwise({redirectTo: '/summary'});
});

当我点击 Transactions 时, 它带我到 Summary

当我从 <a> 更改代码时至 <button> ,它有效,我在这里做错了什么?

最佳答案

http://docs.angularjs.org/api/ng.directive:a

Modifies the default behavior of the html A tag so that the default action is prevented when the href attribute is empty.

关于javascript - angularjs:ng-click <a> 不工作,适用于 <button>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19108223/

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