question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@Inject decorator doesn't seem to work

See original GitHub issue

The @Inject decorator doesn’t seem to work (at least not on a component, which is where I’m testing it).

Just a stab in the dark, but I wonder if this is possibly related to replacing your custom decorator with typedi’s decorator in PR https://github.com/sascha245/vuex-simple/pull/4?

/// SimpleModule.ts

import { Mutation, Module, Getter, State, getStoreBuilder } from 'vuex-simple';

@Module('simple')
export default class SimpleModule
{
    @State() surname = "Baggins";

    @Getter()
    public get formalName()
    {
        return `Mr. ${this.surname}`
    }

    @Mutation()
    public changeName(newName: string)
    {
        this.surname = newName;
    }
}

/// RootComponent.ts
import { Inject } from "typedi";
import Component from "vue-class-component";
import Vue from "vue";
import SimpleModule from "./store/simple/SimpleModule";

@Component({
    template: `
<div style='background: aliceblue; width: 80%; min-height: 100px'>
    {{ formalName }}
</div>
`})
export default class RootComponent extends Vue
{
    /// THIS PROPERTY IS "undefined"
    @Inject()
    simpleModule: SimpleModule

    get formalName() {
        return this.simpleModule.formalName
    }
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
sascha245commented, Oct 10, 2018

Reverted back for now, so we will have to do with the custom Inject provided by vuex-simple. At least with this Inject should now be usable again until I find a good way to make typedi’s Inject work.

1reaction
sascha245commented, Oct 10, 2018

Sorry for being late, was having my lunch. Did you eventually forget the “Vue.use(VuexSimple)”? It is necessary as it installs a Vue mixin that handles the injection of your modules / services in Vue components.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nest.js Injector decorator doesn't seem to register service ...
The service seems to inject correctly, but it does not resolve the dependencies inside the service, leaving me quite confused. Is it possible...
Read more >
Inject() doesn't work, Container.get() does · Issue #93
Hi, I'm facing weird issue, Container.get(MyServiceName); returns demanded service, yet class property decorated with @Inject() is undefined ...
Read more >
Dependency Injection using Decorators | by Chidume Nnamdi
We now see that when ReflectiveInjector creates instances it uses the metadata to deduce class dependencies.
Read more >
How to Use the @Injectable Decorator in Angular
The @Injectable decorator together with the 'providedIn' option means the service should not be added within the providers' array of a module.
Read more >
Angular & Dependency Injection: tricks with Decorators
The SkipSelf Decorator doesn't look for the dependency in the current injector and starts from the parent injector (and then continues to go ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found