Angularjs에서이 작업을 수행하는 방법이 많이 있다는 것을 알고 있습니다. 예를 들어 $ location 등을 사용합니다.
그러나 URL이 다음과 같은 경우 가치를 얻는 방법을 찾을 수 없습니다.
http : // localhost : 8000 / test / 1
해당 URL에서 값 1을 얻는 방법은 무엇입니까?
라우팅을 위해 stateProvider를 사용하고 있습니다.
export default angular.module("examino.userTestSession", ["ui.router"])
.config(function($stateProvider) {
$stateProvider
.state("testing", {
url: "/test",
controller: "UserTestSessionController",
templateUrl: "./app/components/userTestSession/user-test-session.html",
controllerAs: "vm"
})
.state("sessionExpired", {
url: "/sessionExpired",
controller: "UserTestSessionController",
templateUrl: "./app/components/userTestSession/user-test-session-expired.html",
controllerAs: "vm"
});
})
"테스트"상태를 정의 할 때 해당 값을 얻을 수 있습니까?
경로 매개 변수를 :param
노선
export default angular.module("examino.userTestSession", ["ui.router"])
.config(function($stateProvider) {
$stateProvider
.state("testing", {
url: "/test/:id", //Add the parameter here
controller: "UserTestSessionController",
templateUrl: "./app/components/userTestSession/user-test-session.html",
controllerAs: "vm"
})
.state("sessionExpired", {
url: "/sessionExpired",
controller: "UserTestSessionController",
templateUrl: "./app/components/userTestSession/user-test-session-expired.html",
controllerAs: "vm"
});
})
제어 장치
var myId = $stateParams.id
메모
/test/:id
일치 /test/bob
, /test/1235
그리고 /test/
하지만 /test
나/test/bob/other
/test/{id}
이전 것과 동일
/test/{id:int}
매개 변수가 정수로 해석됨을 의미합니다.
/test/{id:[0-9]{1,8}}
ID가 제공된 정규식을 존중해야 함을 의미합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다