ในตัวอย่าง NodeJS ของฉันฉันมี url "localhost: 8080 / Lists / list1.html? x1 = y" ที่ฉันต้องการสำรวจและรับค่า
ในการทำงานร่วมกับ $ location.search () เพื่อรับ x1 = y ฉันได้ทำบางสิ่ง
- ซอร์สสคริปต์ไปยัง angular-route.js
- ใส่ 'ngRoute' ลงในการอ้างอิงของโมดูลแอปของคุณ
- กำหนดค่าตำแหน่งของคุณ
- เพิ่มแท็กฐานสำหรับ $ location (ถ้าคุณไม่ค้นหาการค้นหาของคุณ () x1 จะไม่คืนค่าอะไรเลยหรือไม่ได้กำหนดหรือถ้าแท็กฐานมีข้อมูลที่ไม่ถูกต้องเบราว์เซอร์ของคุณจะไม่สามารถค้นหาไฟล์ของคุณใน script src ที่ .html ของคุณต้องการเปิดแหล่งมุมมองของหน้าเสมอเพื่อทดสอบตำแหน่งไฟล์ของคุณ!)
- เรียกใช้บริการตำแหน่ง (ค้นหา ())
list1.js ของฉันมี
var app = angular.module('NGApp', ['ngRoute']);
app.config(function ($locationProvider) {
$locationProvider.html5Mode(true).hashPrefix('');
});
app.controller('NGCtrl', function ($scope, datasvc, $location) {
var val = $location.search().x1; alert(val);
$scope.xout = function () {
datasvc.out(val)
.then(function (data) {
$scope.x1 = val;
$scope.allMyStuffs = data.all;
});
};
$scope.xout();
});
และ list1.html ของฉันมี
<head>
<base href=".">
</head>
<body ng-controller="NGCtrl">
<div>A<input ng-model="x1"/><br/><textarea ng-model="allMyStuffs"/></div>
<script src="../js/jquery-2.1.4.min.js"></script>
<script src="../js/jquery-ui.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular-route.js"></script>
<script src="../js/bootstrap.min.js"></script>
<script src="../js/ui-bootstrap-tpls-0.14.3.min.js"></script>
<script src="list1.js"></script>
</body>
คำแนะนำ: https://code.angularjs.org/1.2.23/docs/guide/$location
$location.search()
แต่ฉันต้องการตรวจสอบ "วัตถุ" ที่คุณได้รับเมื่อคุณเรียกมันว่า ...