code.cycling
code.cycling

Reputation: 1274

URL link not redirecting properly in Angularjs

I have a link in my announce.obj. But when I clicked it, it's giving me the wrong url (http://www./) in the browser.

html

<p>
  <a ng-href="{{data.links}}" target="_blank">{{data.links}}</a>
</p>

data.links value

www.google.com

Should I add an https when saving my links in the db or something ?

Upvotes: 1

Views: 587

Answers (4)

Sajeetharan
Sajeetharan

Reputation: 222522

you should have the value as,

http://www.google.com

Upvotes: 1

Ramesh Rajendran
Ramesh Rajendran

Reputation: 38663

use target="_self" instead of target="_blank"

angular.module("test",[]).controller("testCont",function($scope)
{
$scope.data={};
$scope.data.links="http://www.google.com/";
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<div ng-app="test" ng-controller="testCont">
  <a ng-href="{{data.links}}" target="_self">{{data.links}}</a>

</div>

Upvotes: 1

Pritam Banerjee
Pritam Banerjee

Reputation: 18923

Try this like $scope.myVar = 'https://www.w3schools.com';:

var app = angular.module('myAngularApp', []);

var myController = app.controller('myController', MyController);

myController.$inject = ['$scope'];

function MyController($scope){

    $scope.myVar = 'https://www.w3schools.com';

}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<html>

<body ng-app="myAngularApp">

<div ng-controller = "myController">
<h1>Tutorials</h1>
<p>Go to <a ng-href="{{myVar}}">{{myVar}}</a> to learn!</p>
</div>

<p>This example could use the original href attribute, but in AngularJS, the ng-href attribute is safer.</p>

</body>
</html>

Upvotes: 2

Shivang Kaul
Shivang Kaul

Reputation: 16

Give the data.links a complete url value, copy it from the mobile browser including the https//: and all , this is a case of the url not beibg recognized.

Upvotes: 0

Related Questions