我的 announce.obj 中有一个链接。但是当我点击它时,它在浏览器中给了我错误的网址(http://www./)。
HTML
<p>
<a ng-href="{{data.links}}" target="_blank">{{data.links}}</a>
</p>
data.links值
www.google.com
在数据库中保存链接时,我应该添加 https 吗?
答案 0 :(得分:2)
请尝试$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>
答案 1 :(得分:1)
你应该将值设为,
NEWID()
答案 2 :(得分:0)
为data.links提供一个完整的url值,从移动浏览器中复制它,包括https //:和all,这是url未被beibg识别的情况。
答案 3 :(得分:0)
使用target="_self"
代替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>