URL link 在 Angularjs 中没有正确重定向
URL link not redirecting properly in Angularjs
我的 announce.obj 中有一个 link。但是当我点击它时,它在浏览器中给了我错误的 url (http://www./)。
html
<p>
<a ng-href="{{data.links}}" target="_blank">{{data.links}}</a>
</p>
data.links值
www.google.com
在数据库中保存 link 时,我应该添加 https 吗?
给data.links一个完整的url值,从手机浏览器复制包括https//:和所有,这是url不被识别的情况.
你的值应该是,
http://www.google.com
试试这个 $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>
使用 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>
我的 announce.obj 中有一个 link。但是当我点击它时,它在浏览器中给了我错误的 url (http://www./)。
html
<p>
<a ng-href="{{data.links}}" target="_blank">{{data.links}}</a>
</p>
data.links值
www.google.com
在数据库中保存 link 时,我应该添加 https 吗?
给data.links一个完整的url值,从手机浏览器复制包括https//:和所有,这是url不被识别的情况.
你的值应该是,
http://www.google.com
试试这个 $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>
使用 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>