如何使用指令和"控制器为"语法的ui-router状态?

Nat*_*han 2 angularjs angular-ui-router

使用ui-router时,我设置如下状态:

$stateProvider
  .state 'product',
    url: '/catalog/product',
    templateUrl: 'app/product/product.html',
Run Code Online (Sandbox Code Playgroud)

唯一的问题是,我的控制器在指令中,而不是作为独立的控制器服务.那么如何告诉ui-router打我的指令而不是模板呢?

否则我不确定如何将模板范围绑定到我的指令中定义的控制器.

Rad*_*ler 5

如果您坚持使用Directive,作为州模板的目标,那么方式将是:

$stateProvider
  .state 'product',
    url: '/catalog/product',
    template: '<div here-is-my-directive-with-all-its-standard-settings></div>',
Run Code Online (Sandbox Code Playgroud)

注意:根本不必controller为视图明确定义.只需将HTML模板注入父级中

指令:

.directive('hereIsMyDirectiveWithAllItsStandardSettings', ...)
Run Code Online (Sandbox Code Playgroud)

换句话说,UI-Router就是处理状态,并注入template.该模板包含指令,它可以按照预期的那样做......

  • 假设它具有隔离范围,您如何将父范围变量传递给模板指令? (3认同)