I've made a simple app similiar to hacker news to understand how works with angularJS.
I have a problem, when I submit link input like:
I type "http://www.foo.com" is submitted and it returns as "www.foo.com"
otherwise, I type "www.foo.com" is submitted and it returns as "localhost:3000/www.foo.com"
I couldn't figure out how to get rid of current location of this url after of submitting a link without HTTP://
There no special conditions to manipulate this link, my app is using a lib for angularjs:
angular-ui-router.js
There is code
HTML:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Link test</title>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.0-beta.5/angular.min.js"></script>
<script src="js.js"></script>
</head>
<body ng-app="scopeExample">
<div ng-controller="MyController">
Your link:
<input type="text" ng-model="url">
<button ng-click='sayLink()'>post link</button>
<hr>
<a ng-href="{{link}}" target="_self">{{link}}</a>
</div>
</body>
</html>
JS:
(function(angular) {
'use strict';
angular.module('scopeExample', [])
.controller('MyController', ['$scope', function($scope) {
$scope.url = 'www.zombo.com';
$scope.sayLink = function() {
$scope.link = $scope.url;
};
}]);
})(window.angular);
There an live preview http://plnkr.co/edit/iDT0C4vi22mGMuxw8z9s?p=preview
Can anyone explain why is this?
Thanks!