html - Using ternary with href in AngularJS -


if type=1, want url use variable {{vm.firstpath}}. else should use {{vm.secondpath}}.

is doable using ternary?

when tried doing not recognised:

{{type==1? <a href="{{vm.firstpath}}">{{vm.name}}</a> : <a href="{{vm.secondpath}}">{{vm.name}}</a>}} 

you should use ng-href istead of href purpose.

 <a ng-href="type == 1 ? 'http://www.google.com' : 'http://www.facebook.com'">link</a>  var app = angular.module('foo', [])   app.controller('main', function($scope){      $scope.type = 1;  }) 

jsfiddle : http://jsfiddle.net/nikdtu/b910258t/


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -