Coder Social home page Coder Social logo

Comments (3)

markostanimirovic avatar markostanimirovic commented on May 27, 2024

Hi @leomayer,

Dependencies need to be injected out of the method body:

withMethods((store, dialog = inject(MatDialog)) => ({
  displayDialog() {
    dialog.open(/* ... */)
  }
}))

or:

withMethods((store) => {
  const dialog = inject(MatDialog);

  return {
    displayDialog() {
      dialog.open(/* ... */)
    },
  };
})

For any further question, feel free to join our Discord Server.

from platform.

leomayer avatar leomayer commented on May 27, 2024

@markostanimirovic : The first solution works, the second not - I get

Uncaught Error: NG0203: inject() must be called from an injection context such as a constructor, a factory function, a field initializer, or a function used with `runInInjectionContext`

Anyway - since I don't care about the difference and I have a running workaround: Thx a lot for your immediate response.

from platform.

markostanimirovic avatar markostanimirovic commented on May 27, 2024

The first snippet is just a shorter version of the second one. In other words, they're equivalent.

Make sure that you copied the code correctly - inject needs to be called within the withMethods factory body, but out of the displayDialog method.

from platform.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.