angularjs – 如何使用Angular 1.5 *组件*和UI Bootstrap模式进行解析

前端之家收集整理的这篇文章主要介绍了angularjs – 如何使用Angular 1.5 *组件*和UI Bootstrap模式进行解析前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用resolve将数据传递到 ubi modal,这是一个Angular 1.5组件.我知道这是可能的,因为它表明uib模式文档中的组件支持resolve.

component (Type: string,Example: myComponent) – A string reference to
the component to be rendered that is registered with Angular’s
compiler. If using a directive,the directive must have restrict: ‘E’
and a template or templateUrl set.

It supports these bindings:

(…)

resolve – An object of the modal resolve values. See UI Router
resolves for details.

我发现的所有示例都在open方法中声明了templateurl / controller.然后将在resolve中声明的项目注入控制器.我将一个Angular 1.5组件传递给模态(不是templateurl / controller),当我尝试从resolve中注入项目时,我遇到了一个可怕的“unknow provider”错误.

这是我的代码.我想通过一个网址.

调用模型的组件控制器

  1. ParentController.$inject = ['$uibModal'];
  2.  
  3. function ParentController $uibModal) {
  4. var $ctrl = this;
  5.  
  6. $ctrl.openComponentModal = function(url) {
  7. var modalInstance = $uibModal.open({
  8. animation: false,component: "ImageModalComponent",resolve: {
  9. url: function() {
  10. return url;
  11. }
  12. }
  13. });
  14. };
  15. }

作为模态的组件中的控制器

  1. ImageModalController.$inject = ['url'];
  2.  
  3. function ImageModalController(url) {
  4. var $ctrl = this;
  5.  
  6. $ctrl.$onInit = function() {
  7. console.log(url);
  8. };
  9.  
  10. }
对于组件,需要将resolve添加到绑定中,然后在隔离范围上提供.换句话说,添加解决方案:’<'在声明组件时. 模态组件
  1. var template = require('./image_modal.component.html');
  2. var ImageModalController = require('./image_modal.controller');
  3.  
  4. module.exports = {
  5. template: template,bindings: {
  6. close: '&',resolve: ‘<‘
  7. },controller: ImageModalController
  8. };

调用模型的组件控制器

  1. ParentController.$inject = ['$uibModal'];
  2. function ParentController $uibModal){
  3. var $ctrl = this;
  4.  
  5. $ctrl.openComponentModal = function (urlFromClickEvent) {
  6. var modalInstance = $uibModal.open({
  7. animation: false,resolve: {
  8. url: function() {
  9. return url;
  10. }
  11. }
  12. });
  13. };
  14. }

作为模态的组件的控制器

  1. ImageModalController.$inject = [];
  2. function ImageModalController() {
  3. var $ctrl = this;
  4. $ctrl.$onInit = function () {
  5. console.log($ctrl.resolve.url);
  6. };
  7. }

猜你在找的Angularjs相关文章