首页 > 代码库 > Angular $location获取端口号

Angular $location获取端口号

<!DOCTYPE html>
<html ng-app="myApp">
<head lang="en">
<meta charset="UTF-8">
<script src="http://www.mamicode.com/js/angular.js"></script>
<title></title>
</head>
<body>
<div ng-controller="myCtrl">
<p>{{nowPort}}</p>
<button ng-click="handleClick()">
得到端口号
</button>
</div>
<script>
var app = angular.module(‘myApp‘, [‘ng‘]);
app.controller(‘myCtrl‘, function ($scope,$location) {
$scope.nowPort = "";
$scope.handleClick = function () {
//获取端口号
$scope.nowPort = $location.port();
}

})
</script>
</body>
</html>

Angular $location获取端口号