我正在使用简单的下拉列表。当我点击下拉菜单时,页面中的函数被调用两次,因此控制器也会调用两次。
这是我的代码:
<div class="dropdown col-md-3">
<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown">{{selectName}}
<span class="caret"></span></button>
<ul class="dropdown-menu">
<li ng-repeat="searchDealer in searchDealers">
<!--<a ui-sref="app.dashboard.v1.summary({searchId: searchDealer.siteId?searchDealer.siteId:0, startDate: (startDate | date: 'MM/dd/yyyy'), endDate: (endDate| date: 'MM/dd/yyyy')})" ui-sref-opts="{reload: true}" ng-click="change(searchDealer)">-->
<a ng-click="loadNewUrl();">
{{searchDealer.dealerName}}
</a>
</li>
</ul>
</div>
$scope.loadNewUrl = function () {
if ($scope.getCurrentPage() === "dashboard") {
$state.go("app.dashboard.v1." + $scope.getCurrentTab(), {searchId: ($stateParams.searchId ? $stateParams.searchId : 0), startDate: $('#startDate').val(), endDate: $('#endDate').val()});
} else if ($scope.getCurrentPage() === "report") {
$state.go("app.report.reports", {searchId: ($stateParams.searchId ? $stateParams.searchId : 0), startDate: $('#startDate').val(), endDate: $('#endDate').val()});
} else if ($scope.getCurrentPage() === "dealer") {
$state.go("app.admin.dealer", {searchId: ($stateParams.searchId ? $stateParams.searchId : 0), startDate: $('#startDate').val(), endDate: $('#endDate').val()});
} else if ($scope.getCurrentPage() === "conversion") {
$state.go("app.conversion.conversion", {searchId: ($stateParams.searchId ? $stateParams.searchId : 0), startDate: $('#startDate').val(), endDate: $('#endDate').val()});
} else {
$location.path("/" + "?startDate=" + $('#startDate').val() + "&endDate=" + $('#endDate').val());
}
};
$scope.getCurrentPage = function () {
var url = window.location.href;
if (url.indexOf("dealer") > 0) {
return "dealer";
}
if (url.indexOf("report") > 0) {
return "report";
}
if (url.indexOf("conversion") > 0) {
return "conversion";
}
return "dashboard";
};
$scope.getCurrentTab = function () {
var url = window.location.href;
if (url.indexOf("url") > 0) {
return "url";
}
if (url.indexOf("media") > 0) {
return "media";
}
return "summary";
};
<!-- end snippet -->