티스토리 뷰

728x90
반응형

ui-router 


ng-route를 보강한 라이브러리


주소: https://ui-router.github.io/ng1/docs/0.3.1/index.html#/api/ui.router 

( 해당 주소로 가보면 튜토리얼도 잘 나와 있다. 하지만 아직도 헷갈림  )




.config()로 설정.


아래 기본 js 구성

angular.module('모듈이름', [
'ui.router',
'의존 모듈이름'

]).config(function($stateProvider, $urlRouterProvider ){
$stateProvider.state('state 이름', {
url:'',

templateUrl:'템플릿파일 경로', //or template:'템플릿 html코드'

controller:'컨트롤러이름'
})
})

//아래와 같이 html 구성시 ( view 구성이 2개 이다 )

<!-- 아래처럼 ui-view 라는 attribute 로 지정할 수 있다. / 엘리먼트 지정도 가능 -->

<div class="row">
<div class="col-sm-3 col-md-2 sidebar" ui-view="stateView1"></div>
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2" ui-view="stateView2"></div>
</div>

........중략..........................


<!-- 아래처럼 angular-ui-router.min.js 로드 시킴 별도로 다운받아야 한다. -->

<script src="angular-ui-router.min.js"></script>

// ui-view가 2개 이기에 이 두개의 ui-view를 그룹화 및 기본 추상화 상속을 해주는..

// 즉 아래처럼 abstract 속성지정으로

// 추상화(부모) 할 수 있다.

angular.module('모듈이름', [
'ui.router',
'demo1',

'demo2',
]).config(function($stateProvider, $urlRouterProvider ){
$stateProvider.state('state 이름', {
url:'', //최상위 root인 경우 빈공백이면 됨.
abstract:true //추상화 - 부모 상속 시킴.
})
$urlRouterProvider.otherwise('/'); //없는 경로일 경우 루트 경로이동.

})

//아래는 demo1

angular.module("demo1", []).config(function($stateProvider) {
$stateProvider.state('eggly.categories', {
url:'/', // 최상위로 지정.
views:{ // ui-view가 여러개일 경우 views라는 속성을 지정하여 아래처럼 구성가능.
'stateView1@':{ // html 에 ui-view="stateView1"라고 지정되어 있다.
controller:'ListCtrl as listCtrl',
templateUrl:'템플릿 파일 경로'
},
'stateView2@':{ // html 에 ui-view="stateView2"라고 지정되어 있다.
controller:'ListCtrl2 as listCtrl2',
templateUrl:'템플릿 파일 경로'
}
}
})
}).controller('ListCtrl', ListCtrl() {

}).controller('ListCtrl2', ListCtrl2() {


})


아래처럼 $state.go라는 함수 or html에서는 ui-sref="{}"이라는 attribute로  view상태 전환.( 지정한 state로 전환 )

형식: $state.go( "state 이름", { params 객체} )


형식: ui-sref="state 이름( { params 객체 } )"   // state이름() --> 이건 함수의 형태를 말함.


state 이름 --> 지정된 character를 적용 할 수 있다.

  •  ‘.’: 현재의 state를 가리킴.
  •  ‘.child’로 쓰면 현재 state를 기준으로 child를 추가한 state로 이동.
  • ‘^’: 부모의 state. 

- $stateParams: params객체에 지정된 값은 $stateParams에 저장됨.

728x90
반응형

'Programming language > Angularjs(1.x)' 카테고리의 다른 글

angular toastr  (0) 2017.01.24
yeoman gulp설정 - generator-yo-gulp / gulp-ng-config/  (0) 2017.01.24
angularjs 에서 Service/Factory  (0) 2016.10.18
gulp 설정  (0) 2016.04.20
angularjs 정리3 ngApp/ngBind  (0) 2015.12.03
댓글