如何使用angularJs使URL动态

时间:2019-01-14 06:37:15

标签: html angularjs

需要将这三个锚标记合并为一个,并且href必须是动态的。下面是我的代码:

<a ng-if="ctrl.currentState == 'driver'" id="back-button" href="/driver/quoting/app/search/"></a>
<a ng-if="ctrl.currentState == 'employee'" id="employeeBackButton" href="/driver/quoting/app/employee/search"></a>
<a ng-if="ctrl.currentState == 'fleetmanager'" id="fleetmanagerBackButton" href="/driver/quoting/app/fleetmanager/search"></a>

1 个答案:

答案 0 :(得分:0)

您可以在此处使用ngHref

// In your controller 

if ($scope.currentState) == 'driver') {
    $scope.myUrl = '/driver/quoting/app/search/';
    $scope.myButtonId = 'back-button';
else if ($scope.currentState == 'employee') {  
    $scope.myUrl = '/driver/quoting/app/employee/search';
    $scope.myButtonId = 'employeeBackButton';
else if ($scope.currentState == 'fleetmanager') {  
    $scope.myUrl = '/driver/quoting/app/fleetmanager/search';        
    $scope.myButtonId = 'fleetmanagerBackButton';
}

并在下面的HTML视图中使用

<a ng-href="{{myUrl}}" title="URL" ng-attr-id="{{myButtonId}}" ></a>

希望获得帮助!