Angularjs href in controller












1















I was previous having 2 links where user can click and link them to another page, but now, I would like to have an option list where user can choose and link them as well. How can I achieve that? I was doing it previous by this method



<a ng-href="LINK" ng-click="getKML(selectedTheme)" target="_blank" download>KML</a>
<a ng-href="LINK" ng-click="getSHP(selectedTheme)" target="_blank" download>KML</a>


But now, I would like to have an option list to do the same thing, how can I achieve that?






angular.module('MyApp', ['ngMaterial', 'ngMessages', 'material.svgAssetsCache'])
.controller('AppCtrl', function($scope, $mdDialog) {
$scope.downloadFormat = ["a", "b"];
});

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>angular Js Modal popup</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
<link rel='stylesheet' href='https://cdn.gitcdn.link/cdn/angular/bower-material/v1.1.1/angular-material.css'>
<link rel='stylesheet' href='https://material.angularjs.org/1.1.1/docs.css'>
<link rel="stylesheet" href="css/style.css">
</head>

<body ng-controller="AppCtrl" ng-app="MyApp">
<select ng-model="selectedFormat" ng-options="x for x in downloadFormat">
</select>
<button ng-click="lalalu(selectedFormat)">Download</button>
<!--
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that can be foundin the LICENSE file at https://material.angularjs.org/HEAD/license.
-->
<script src='https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.min.js'></script>
<script src='https://cdn.gitcdn.link/cdn/angular/bower-material/v1.1.1/angular-material.js'></script>
<script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-animate.min.js'></script>
<script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-route.min.js'></script>
<script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-aria.min.js'></script>
<script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-messages.min.js'></script>
<script src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/t-114/svg-assets-cache.js'></script>
<script src="js/index.js"></script>
</body>

</html>












share|improve this question

























  • Stackblitz or any code example?

    – Prashant Pimpale
    Nov 16 '18 at 6:05











  • @PrashantPimpale i added a snippet

    – ITnyp
    Nov 16 '18 at 6:19
















1















I was previous having 2 links where user can click and link them to another page, but now, I would like to have an option list where user can choose and link them as well. How can I achieve that? I was doing it previous by this method



<a ng-href="LINK" ng-click="getKML(selectedTheme)" target="_blank" download>KML</a>
<a ng-href="LINK" ng-click="getSHP(selectedTheme)" target="_blank" download>KML</a>


But now, I would like to have an option list to do the same thing, how can I achieve that?






angular.module('MyApp', ['ngMaterial', 'ngMessages', 'material.svgAssetsCache'])
.controller('AppCtrl', function($scope, $mdDialog) {
$scope.downloadFormat = ["a", "b"];
});

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>angular Js Modal popup</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
<link rel='stylesheet' href='https://cdn.gitcdn.link/cdn/angular/bower-material/v1.1.1/angular-material.css'>
<link rel='stylesheet' href='https://material.angularjs.org/1.1.1/docs.css'>
<link rel="stylesheet" href="css/style.css">
</head>

<body ng-controller="AppCtrl" ng-app="MyApp">
<select ng-model="selectedFormat" ng-options="x for x in downloadFormat">
</select>
<button ng-click="lalalu(selectedFormat)">Download</button>
<!--
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that can be foundin the LICENSE file at https://material.angularjs.org/HEAD/license.
-->
<script src='https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.min.js'></script>
<script src='https://cdn.gitcdn.link/cdn/angular/bower-material/v1.1.1/angular-material.js'></script>
<script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-animate.min.js'></script>
<script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-route.min.js'></script>
<script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-aria.min.js'></script>
<script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-messages.min.js'></script>
<script src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/t-114/svg-assets-cache.js'></script>
<script src="js/index.js"></script>
</body>

</html>












share|improve this question

























  • Stackblitz or any code example?

    – Prashant Pimpale
    Nov 16 '18 at 6:05











  • @PrashantPimpale i added a snippet

    – ITnyp
    Nov 16 '18 at 6:19














1












1








1








I was previous having 2 links where user can click and link them to another page, but now, I would like to have an option list where user can choose and link them as well. How can I achieve that? I was doing it previous by this method



<a ng-href="LINK" ng-click="getKML(selectedTheme)" target="_blank" download>KML</a>
<a ng-href="LINK" ng-click="getSHP(selectedTheme)" target="_blank" download>KML</a>


But now, I would like to have an option list to do the same thing, how can I achieve that?






angular.module('MyApp', ['ngMaterial', 'ngMessages', 'material.svgAssetsCache'])
.controller('AppCtrl', function($scope, $mdDialog) {
$scope.downloadFormat = ["a", "b"];
});

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>angular Js Modal popup</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
<link rel='stylesheet' href='https://cdn.gitcdn.link/cdn/angular/bower-material/v1.1.1/angular-material.css'>
<link rel='stylesheet' href='https://material.angularjs.org/1.1.1/docs.css'>
<link rel="stylesheet" href="css/style.css">
</head>

<body ng-controller="AppCtrl" ng-app="MyApp">
<select ng-model="selectedFormat" ng-options="x for x in downloadFormat">
</select>
<button ng-click="lalalu(selectedFormat)">Download</button>
<!--
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that can be foundin the LICENSE file at https://material.angularjs.org/HEAD/license.
-->
<script src='https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.min.js'></script>
<script src='https://cdn.gitcdn.link/cdn/angular/bower-material/v1.1.1/angular-material.js'></script>
<script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-animate.min.js'></script>
<script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-route.min.js'></script>
<script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-aria.min.js'></script>
<script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-messages.min.js'></script>
<script src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/t-114/svg-assets-cache.js'></script>
<script src="js/index.js"></script>
</body>

</html>












share|improve this question
















I was previous having 2 links where user can click and link them to another page, but now, I would like to have an option list where user can choose and link them as well. How can I achieve that? I was doing it previous by this method



<a ng-href="LINK" ng-click="getKML(selectedTheme)" target="_blank" download>KML</a>
<a ng-href="LINK" ng-click="getSHP(selectedTheme)" target="_blank" download>KML</a>


But now, I would like to have an option list to do the same thing, how can I achieve that?






angular.module('MyApp', ['ngMaterial', 'ngMessages', 'material.svgAssetsCache'])
.controller('AppCtrl', function($scope, $mdDialog) {
$scope.downloadFormat = ["a", "b"];
});

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>angular Js Modal popup</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
<link rel='stylesheet' href='https://cdn.gitcdn.link/cdn/angular/bower-material/v1.1.1/angular-material.css'>
<link rel='stylesheet' href='https://material.angularjs.org/1.1.1/docs.css'>
<link rel="stylesheet" href="css/style.css">
</head>

<body ng-controller="AppCtrl" ng-app="MyApp">
<select ng-model="selectedFormat" ng-options="x for x in downloadFormat">
</select>
<button ng-click="lalalu(selectedFormat)">Download</button>
<!--
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that can be foundin the LICENSE file at https://material.angularjs.org/HEAD/license.
-->
<script src='https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.min.js'></script>
<script src='https://cdn.gitcdn.link/cdn/angular/bower-material/v1.1.1/angular-material.js'></script>
<script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-animate.min.js'></script>
<script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-route.min.js'></script>
<script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-aria.min.js'></script>
<script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-messages.min.js'></script>
<script src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/t-114/svg-assets-cache.js'></script>
<script src="js/index.js"></script>
</body>

</html>








angular.module('MyApp', ['ngMaterial', 'ngMessages', 'material.svgAssetsCache'])
.controller('AppCtrl', function($scope, $mdDialog) {
$scope.downloadFormat = ["a", "b"];
});

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>angular Js Modal popup</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
<link rel='stylesheet' href='https://cdn.gitcdn.link/cdn/angular/bower-material/v1.1.1/angular-material.css'>
<link rel='stylesheet' href='https://material.angularjs.org/1.1.1/docs.css'>
<link rel="stylesheet" href="css/style.css">
</head>

<body ng-controller="AppCtrl" ng-app="MyApp">
<select ng-model="selectedFormat" ng-options="x for x in downloadFormat">
</select>
<button ng-click="lalalu(selectedFormat)">Download</button>
<!--
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that can be foundin the LICENSE file at https://material.angularjs.org/HEAD/license.
-->
<script src='https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.min.js'></script>
<script src='https://cdn.gitcdn.link/cdn/angular/bower-material/v1.1.1/angular-material.js'></script>
<script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-animate.min.js'></script>
<script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-route.min.js'></script>
<script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-aria.min.js'></script>
<script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-messages.min.js'></script>
<script src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/t-114/svg-assets-cache.js'></script>
<script src="js/index.js"></script>
</body>

</html>





angular.module('MyApp', ['ngMaterial', 'ngMessages', 'material.svgAssetsCache'])
.controller('AppCtrl', function($scope, $mdDialog) {
$scope.downloadFormat = ["a", "b"];
});

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>angular Js Modal popup</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
<link rel='stylesheet' href='https://cdn.gitcdn.link/cdn/angular/bower-material/v1.1.1/angular-material.css'>
<link rel='stylesheet' href='https://material.angularjs.org/1.1.1/docs.css'>
<link rel="stylesheet" href="css/style.css">
</head>

<body ng-controller="AppCtrl" ng-app="MyApp">
<select ng-model="selectedFormat" ng-options="x for x in downloadFormat">
</select>
<button ng-click="lalalu(selectedFormat)">Download</button>
<!--
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that can be foundin the LICENSE file at https://material.angularjs.org/HEAD/license.
-->
<script src='https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.min.js'></script>
<script src='https://cdn.gitcdn.link/cdn/angular/bower-material/v1.1.1/angular-material.js'></script>
<script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-animate.min.js'></script>
<script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-route.min.js'></script>
<script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-aria.min.js'></script>
<script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-messages.min.js'></script>
<script src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/t-114/svg-assets-cache.js'></script>
<script src="js/index.js"></script>
</body>

</html>






javascript angularjs






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 6:42









Krupesh Kotecha

2,07311136




2,07311136










asked Nov 16 '18 at 6:03









ITnypITnyp

628




628













  • Stackblitz or any code example?

    – Prashant Pimpale
    Nov 16 '18 at 6:05











  • @PrashantPimpale i added a snippet

    – ITnyp
    Nov 16 '18 at 6:19



















  • Stackblitz or any code example?

    – Prashant Pimpale
    Nov 16 '18 at 6:05











  • @PrashantPimpale i added a snippet

    – ITnyp
    Nov 16 '18 at 6:19

















Stackblitz or any code example?

– Prashant Pimpale
Nov 16 '18 at 6:05





Stackblitz or any code example?

– Prashant Pimpale
Nov 16 '18 at 6:05













@PrashantPimpale i added a snippet

– ITnyp
Nov 16 '18 at 6:19





@PrashantPimpale i added a snippet

– ITnyp
Nov 16 '18 at 6:19












1 Answer
1






active

oldest

votes


















1














You can use $location service to achieve this, you can redirect your user to other website using this service. Please refer to the plunker below, select a link from the dropdown and it redirect you to that website :






var app = angular.module('main',);
app.controller('myctrl', function($scope, $location, $window){
$scope.downloadFormat = ["https://code.angularjs.org/1.2.18/docs/"];
$scope.redirectToSite = function(site){
if($scope.$$phase) { // check is digest cycle is already running
$window.location.href = site;
} else {
$location.url(site);
$scope.$apply();
}
};
});

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.18/angular.min.js"></script>
<div ng-app="main">
<div ng-controller="myctrl">
<select ng-model="selectedFormat" ng-options="x for x in downloadFormat">
</select>
<button ng-click="redirectToSite(selectedFormat)">Redirect</button>
</div>
</div>








share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53332290%2fangularjs-href-in-controller%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    You can use $location service to achieve this, you can redirect your user to other website using this service. Please refer to the plunker below, select a link from the dropdown and it redirect you to that website :






    var app = angular.module('main',);
    app.controller('myctrl', function($scope, $location, $window){
    $scope.downloadFormat = ["https://code.angularjs.org/1.2.18/docs/"];
    $scope.redirectToSite = function(site){
    if($scope.$$phase) { // check is digest cycle is already running
    $window.location.href = site;
    } else {
    $location.url(site);
    $scope.$apply();
    }
    };
    });

    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.18/angular.min.js"></script>
    <div ng-app="main">
    <div ng-controller="myctrl">
    <select ng-model="selectedFormat" ng-options="x for x in downloadFormat">
    </select>
    <button ng-click="redirectToSite(selectedFormat)">Redirect</button>
    </div>
    </div>








    share|improve this answer




























      1














      You can use $location service to achieve this, you can redirect your user to other website using this service. Please refer to the plunker below, select a link from the dropdown and it redirect you to that website :






      var app = angular.module('main',);
      app.controller('myctrl', function($scope, $location, $window){
      $scope.downloadFormat = ["https://code.angularjs.org/1.2.18/docs/"];
      $scope.redirectToSite = function(site){
      if($scope.$$phase) { // check is digest cycle is already running
      $window.location.href = site;
      } else {
      $location.url(site);
      $scope.$apply();
      }
      };
      });

      <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.18/angular.min.js"></script>
      <div ng-app="main">
      <div ng-controller="myctrl">
      <select ng-model="selectedFormat" ng-options="x for x in downloadFormat">
      </select>
      <button ng-click="redirectToSite(selectedFormat)">Redirect</button>
      </div>
      </div>








      share|improve this answer


























        1












        1








        1







        You can use $location service to achieve this, you can redirect your user to other website using this service. Please refer to the plunker below, select a link from the dropdown and it redirect you to that website :






        var app = angular.module('main',);
        app.controller('myctrl', function($scope, $location, $window){
        $scope.downloadFormat = ["https://code.angularjs.org/1.2.18/docs/"];
        $scope.redirectToSite = function(site){
        if($scope.$$phase) { // check is digest cycle is already running
        $window.location.href = site;
        } else {
        $location.url(site);
        $scope.$apply();
        }
        };
        });

        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.18/angular.min.js"></script>
        <div ng-app="main">
        <div ng-controller="myctrl">
        <select ng-model="selectedFormat" ng-options="x for x in downloadFormat">
        </select>
        <button ng-click="redirectToSite(selectedFormat)">Redirect</button>
        </div>
        </div>








        share|improve this answer













        You can use $location service to achieve this, you can redirect your user to other website using this service. Please refer to the plunker below, select a link from the dropdown and it redirect you to that website :






        var app = angular.module('main',);
        app.controller('myctrl', function($scope, $location, $window){
        $scope.downloadFormat = ["https://code.angularjs.org/1.2.18/docs/"];
        $scope.redirectToSite = function(site){
        if($scope.$$phase) { // check is digest cycle is already running
        $window.location.href = site;
        } else {
        $location.url(site);
        $scope.$apply();
        }
        };
        });

        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.18/angular.min.js"></script>
        <div ng-app="main">
        <div ng-controller="myctrl">
        <select ng-model="selectedFormat" ng-options="x for x in downloadFormat">
        </select>
        <button ng-click="redirectToSite(selectedFormat)">Redirect</button>
        </div>
        </div>








        var app = angular.module('main',);
        app.controller('myctrl', function($scope, $location, $window){
        $scope.downloadFormat = ["https://code.angularjs.org/1.2.18/docs/"];
        $scope.redirectToSite = function(site){
        if($scope.$$phase) { // check is digest cycle is already running
        $window.location.href = site;
        } else {
        $location.url(site);
        $scope.$apply();
        }
        };
        });

        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.18/angular.min.js"></script>
        <div ng-app="main">
        <div ng-controller="myctrl">
        <select ng-model="selectedFormat" ng-options="x for x in downloadFormat">
        </select>
        <button ng-click="redirectToSite(selectedFormat)">Redirect</button>
        </div>
        </div>





        var app = angular.module('main',);
        app.controller('myctrl', function($scope, $location, $window){
        $scope.downloadFormat = ["https://code.angularjs.org/1.2.18/docs/"];
        $scope.redirectToSite = function(site){
        if($scope.$$phase) { // check is digest cycle is already running
        $window.location.href = site;
        } else {
        $location.url(site);
        $scope.$apply();
        }
        };
        });

        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.18/angular.min.js"></script>
        <div ng-app="main">
        <div ng-controller="myctrl">
        <select ng-model="selectedFormat" ng-options="x for x in downloadFormat">
        </select>
        <button ng-click="redirectToSite(selectedFormat)">Redirect</button>
        </div>
        </div>






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 16 '18 at 6:21









        amrender singhamrender singh

        5,0811920




        5,0811920
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53332290%2fangularjs-href-in-controller%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Bressuire

            Vorschmack

            Quarantine