Angular วิธีการใช้งาน Query string อย่างง่าย : Angular easy to use query string


การรับส่งค่าระหว่างหน้าของเว็บ วิธีการหนึ่งที่นิยมใช้กันคือส่งผ่าน query string หรือติดไปกับ url นั้นเอง ซึ่งวันนี้จะมานำเสนอวิธีการสร้าง query string  ของ angular และวิธีการรับค่าผ่านทาง query string นั้นทำอย่างไร
  1. วิธีการส่งค่าผ่าน Query string  angularjs
    • injector ที่ใช้คือ $location เป็นตัวหลักในการ redirect และการ pass argument ไปด้วยโดยใช้คำสั่ง 
    • $location.path('/redirect-path').search('argument','value');
  2. วิธีการรับค่าผ่าน Query string angularjs
    • injector ทีใช้คือ $location โดยมีคำสั่ง
    • $location.search(). argument;
  3. ตัวอย่าง code 
  4. (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');
    }]);
    }());
    view raw simpleApp.js hosted with ❤ by GitHub



Share on Google Plus

About maxcom

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 ความคิดเห็น:

แสดงความคิดเห็น