inject

{ inject : { $router : {}, someService : {} } }

Properties to inject into the component. These will be attached to the component instance. This uses vue-inject to resolve the injected values and attach them during the beforeCreate hook.

If you pass a function as an injected property, vuenit will assume it is a factory function and will return the result of the function:

{
  inject : {
    myFactory(){
      return {};
    }
  }
}

This also means you can leverage vue-inject's dependency injection:

{
  inject : {
    myFactory($timeout, $log){
      return function(m){
        $timeout(() => $log(m), 250);
      };
    }
  }
}

However, this feature also means that if you want to inject a function into your component, you must wrap it in another function, otherwise it will be invoked as a factory:

{
  inject : {
    $http : $http, // if $http is a function, this will not work
    $http : () => $http // will work
  }
}

results matching ""

    No results matching ""