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

时间:2015-03-02 00:38:09

标签: angularjs angular-ui-router

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

$stateProvider
  .state 'product',
    url: '/catalog/product',
    templateUrl: 'app/product/product.html',

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

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

1 个答案:

答案 0 :(得分:5)

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

$stateProvider
  .state 'product',
    url: '/catalog/product',
    template: '<div here-is-my-directive-with-all-its-standard-settings></div>',

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

指令:

.directive('hereIsMyDirectiveWithAllItsStandardSettings', ...)

换句话说,UI-Router处理状态,并注入 template 。该模板包含指令,该指令可以执行为...设计的预期...

相关问题