小编wta*_*iro的帖子

如何在角度1.5中使用ui.bootstrap.modal的角度分量?

我想在ui.bootstrap.modal中使用angular组件.角度版本是1.5.
我尝试使用如下.

零件

function MyComponentController($uibModalInstance){
  var ctrl = this;

  ctrl.doSomething = function() {
    //doSomething
  }
}

app.component('myComponent', {
  contoller: MyComponentController,
  templateUrl: '/path/to/myComponent.html'
}
Run Code Online (Sandbox Code Playgroud)

父控制器

function parentController($uibModal){
  var ctrl = this;

  ctrl.openModal = function(){
    var modalInstance = $uibModal.open({
      template: '<my-component></my-component>'

  }
}
Run Code Online (Sandbox Code Playgroud)

当我执行时parentController.openModal(),我得到了$ injector:unpr未知提供程序的错误,虽然模态窗口是打开的.
有没有办法在ui.bootstrap.modal中使用角度组件?如果您需要更多信息,请告诉我.
谢谢.

编辑
我有一种方法可以使用来自Renato Machado的ui.bootstrap.modal组件,感谢Renato.
但我觉得它有点复杂,不方便.所以最后我认为在模态中使用组件会更好.
Modal以常规方式打开(只需设置控制器和模板$uibModal.open({})),模态包含具有您想要常用的逻辑的组件.
模态应该只有与模态相关的简单逻辑,如关闭模态窗口.
另一个主要与业务/应用程序相关的逻辑应该在组件中.
它很容易共同化.

javascript angularjs angular-ui-bootstrap

40
推荐指数
3
解决办法
4万
查看次数