การรับส่งค่าระหว่างหน้าของเว็บ วิธีการหนึ่งที่นิยมใช้กันคือส่งผ่าน query string หรือติดไปกับ url นั้นเอง ซึ่งวันนี้จะมานำเสนอวิธีการสร้าง query string ของ angular และวิธีการรับค่าผ่านทาง query string นั้นทำอย่างไร
- วิธีการส่งค่าผ่าน Query string angularjs
- injector ที่ใช้คือ $location เป็นตัวหลักในการ redirect และการ pass argument ไปด้วยโดยใช้คำสั่ง
- $location.path('/redirect-path').search('argument','value');
- วิธีการรับค่าผ่าน Query string angularjs
- injector ทีใช้คือ $location โดยมีคำสั่ง
- $location.search(). argument;
- ตัวอย่าง code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
var simpleApp = angular.module('simpleApp', []); | |
simpleApp.controller('simpleController', ['$location',function($location){ | |
/** receive data */ | |
var id = $location.search().id; | |
console.log(id); | |
/** send argument */ | |
$location.path('/redirect-path').search('id','1234'); | |
}]); | |
}()); |
0 ความคิดเห็น:
แสดงความคิดเห็น