code

ui-module:뷰 템플릿이 없는 루트

starcafe 2023. 3. 9. 22:12
반응형

ui-module:뷰 템플릿이 없는 루트

에서 루트를 셋업할 수 있습니까?ui-router콘트롤러만 있는 건가요?그 목적은 특정 URL에서 제가 하고 싶은 것은 단지 뷰에 아무것도 표시하지 않고 프로그램적으로 행동하는 것입니다.그 문서들은 다 읽었지만, 그들이 이걸 어떻게 할 수 있는지 잘 모르겠어요.

네, 저는 https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-open-a-dialogmodal-at-a-certain-state,을 읽었습니다만, 그것은 제가 찾고 있는 것이 아닙니다.

예를 들어, 기본적인 신체에 시야가 있다고 합시다.

<body ui-view></body>

또, 기본적인 설정:

// Routes
$stateProvider
  .state('myaction', {
    url: "/go/myaction",
    onEnter: function() {
      console.log('doing something');
    }
  });

언제/go/myaction뷰는 공백입니다.이거 할 수 있어요?

이 문제를 해결할 수 있는 방법은 프로그램 액션을 수행하던 헤드가 없는 상태를 헤드가 없는 상태의 끝에 뷰가 있는 상태로 수정하는 것입니다.

$stateProvider
  .state('myaction', {
    url: "/go/myaction",
    onEnter: function() {
      console.log('doing something');
    }
    controller: function($state) {
      $state.go('home');
    }
  });

뷰가 없으면 컨트롤러를 가질 수 없지만onEnter컨트롤러 대신.이 상태에 액세스할 때 현재 보기를 변경하지 않으려면 하위 상태로 정의할 수 있습니다.

$stateProvider

   // the parent state with a template
   .state('home', {
      url: '/home',
      templateUrl: '/home.html',
      controller: 'HomeCtrl'
   })

   // child of the 'home' state with no view
   .state('home.action', {
      url: '/action',
      onEnter: function() {
         alert('Hi');
      },
   });

자, 들어가겠습니다.home.html다음과 같은 작업을 수행할 수 있습니다.

<a href ui-sref=".action">Greet me!</a>

문서에서:

경고:템플릿이 정의되지 않은 경우 컨트롤러는 인스턴스화되지 않습니다.

이를 극복하기 위해 빈 문자열을 템플릿으로 사용하는 것은 어떨까요?

네, 할 수 있어요.절대이름을 사용하여 다시 사용<ui-view>다른 주(州)의

다음 예를 참조하십시오.

사용자는 내 앱에 접속하지만, 인증 여부에 따라서는 공개 페이지나 비공개 페이지로 전송하고 싶습니다.사용하다index단순히 로그인 여부를 확인하고 다음으로 리다이렉트합니다.index.private또는index.public.

하위 상태는 절대이름을 사용하여<ui-view>대응하는 요소index이렇게 하면 두 번째 네스트를 하지 않아도 됩니다.<ui-view>.

$stateProvider.state('index', {
  url: "/",
  controller: 'IndexCtrl'
}).state('index.private', {
  views: {
    "@": {
      templateUrl: 'private.html',
      controller: 'PrivateCtrl'
    }
  }
}).state('index.public', {
  views: {
    "@": {
      templateUrl: 'public.html',
      controller: 'PublicCtrl'
    }
  }
});

이 예에 대한 주의사항:를 사용하고 있습니다.@숏컷을 클릭합니다.일반적으로는viewname@statename.

이에 대한 저의 해결책은 빈 템플릿(html 파일)을 포함시키는 것이었습니다.

언급URL : https://stackoverflow.com/questions/19171655/ui-router-a-route-with-no-view-template

반응형