VANHIEP.NET - Làm web giá rẻ - Thiết Kế Website - Thiết Kế Ứng Dụng Mobile

Cách gửi dữ liệu lên url trong angularjs route

Cách gửi dữ liệu lên url trong angularjs route

Chúng ta khai báo route như sau

var app = angular.module("myApp", ["ngRoute"]);
app.config(function($routeProvider) {
  $routeProvider
  .when("/", {
    templateUrl : "main.htm"
  })
  .when("/london", {
    templateUrl : "london.htm",
    controller : "londonCtrl"
  })
  .when("/paris", {
    templateUrl : "paris.htm",
    controller : "parisCtrl"
  });
});
app.controller("londonCtrl", function ($scope) {
  $scope.msg = "I love London";
});
app.controller("parisCtrl", function ($scope) {
  $scope.msg = "I love Paris";
});

Truyền params và nhận params trong controller như sau

when(url: '/new/:portfolioId',
    templateUrl: 'new.html',
    controller: function($scope, $stateParams) {
      $scope.portfolioId = $stateParams.portfolioId;
    }
  )

Chúc bạn thành công !