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
Post a Comment