AngularJS: $stateProvider move code to template

时间:2017-08-04 12:41:32

标签: angularjs angular-ui-router

I have next view.html for example:

<div>
  <h1> Block 1 </h1>
  <div>
    <h1> Block 2 </h1>
  </div>
</div>

in js file

$stateProvider
        .state('blocks', {
            url: '/blocks',
            template: require('./view.html'),
            controller: 'MainController',
            controllerAs: 'ctrl'
        })

And it works. But i want to move "Block 2" to template. And i created ./units/block2.html

view.html:

<div>
  <h1> Block 1 </h1>
  <div ui-view="block2"/>
</div

js file:

$stateProvider
    .state('blocks', {
         url: '/blocks',
         template: require('./view.html'),
         controller: 'MainController',
         controllerAs: 'ctrl'
    })
    .state('blocks.block2', {   
        views: {
            'block2@blocks.block2': {
                templateUrl: "./units/block2.html"
            }
        }
    })
}

What is wrong? I try next ways - and i can not see content from block2:

template: require('./units/block2.html')

'block2': {
         template: require('./units/block2.html')

0 个答案:

没有答案