0

I want to pass a data from the state to the controller, I would like the {{ projectName }} be interpreted at the state level (this state) and returns its value (string) directly to the controller.

Is there a way to do this by the resolve (the code in the resolve was only for the test, but we can in fact retrieve the projectName by ProjectUtilService.getProjectName(project)) or the onEnter method or for example to execute a function at the same level of data.title and which return the projectName ...?

.state({
    name: 'project.detail.edit.headers.overlay.comment',
    url: '/comment',
    data: {
        title: '{{ projectName }}'
    },
    component: 'iadAgentMyIadComment',
    resolve: {
        projectName: (project, ProjectUtilService) => {
            ProjectUtilService.getProjectName(project)
        }
    }
})

EDIT :

  getProjectName(project) {
    return project.contactName
  }

for example if ProjectUtilService.getProductName (project) returns "Richard Stallman" i want i found on my controller this.$state.current.data.title which is equal to Richard Stallman

Mouad Ennaciri
  • 1,217
  • 3
  • 15
  • 28
  • If you are trying to pass data from one state to another you can use state params.. – Raghav Sep 27 '17 at 10:53
  • Is [this](https://stackoverflow.com/a/40114183/2810683) what you want? – Marius P. Sep 27 '17 at 11:08
  • I would advise against mutating any data on `$state.current.data`. Instead, add a binding on your component which receives the `projectName` resolve. https://ui-router.github.io/guide/ng1/route-to-component#resolve-bindings – Chris T Sep 29 '17 at 01:20

0 Answers0