Angular 1 / Ui-router - 将数据从状态传递到控制器

时间:2022-02-26 03:21:07

Here is my state :

这是我的状态:

.state({
  name: 'contact.detail.read.step.overlay',
  url: '',
  abstract: true,
  data: {
    skipFooter: true,
    cancelState: 'contact.detail.read'
  },
  views: {
    'overlay@agent': {
      component: 'overlayContent'
    }
  }
})

I want to run a method in this state that retrieves the name of the contact (contactName) and that it is recognized in the controller overlayContent

我想在这种状态下运行一个方法来检索联系人的名字(contactName),并在控制器overlayContent中识别它。

normally I can access contact name in the overlayContent controller if I add it to the bindings with :

通常我可以访问overlayContent控制器中的联系人名称,如果我将其添加到绑定:

  bindings: {
    contactName: '<'
  }

but I'm looking for a solution that does it without changing the bindings from the state, by adding it for example in the parameter data :

但我正在寻找一种解决方案,它可以在不改变状态绑定的情况下通过在参数数据中添加它来实现:

  data: {
    name: contactName,
    skipFooter: true,
    cancelState: 'contact.detail.read'
  },

1 个解决方案

#1


0  

You could resolve contactName:

您可以解析contactName:

.state({
  name: 'contact.detail.read.step.overlay',
  url: '',
  abstract: true,
  data: {
    skipFooter: true,
    cancelState: 'contact.detail.read'
  },
  views: {
    'overlay@agent': {
      component: 'overlayContent'
    }
  },
  resolve: {
    contactName: () => {
      return 'what ever contactName should be';
    }
  }
})

#1


0  

You could resolve contactName:

您可以解析contactName:

.state({
  name: 'contact.detail.read.step.overlay',
  url: '',
  abstract: true,
  data: {
    skipFooter: true,
    cancelState: 'contact.detail.read'
  },
  views: {
    'overlay@agent': {
      component: 'overlayContent'
    }
  },
  resolve: {
    contactName: () => {
      return 'what ever contactName should be';
    }
  }
})