1

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 ?

4 Answers 4

2

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>

Sign up to request clarification or add additional context in comments.

Comments

1

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>

1 Comment

then try with full url and check this : stackoverflow.com/questions/19773682/… @Priz
1

you should have the value as,

http://www.google.com

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.