ng-classify
ng-classify copied to clipboard
Resolve dependency injection
When using resolve for ex with the "messages" var.. throws DI error.. because its loaded in the array as a dependency.. but its not.
Is there a way of avoiding this? Thanks!
ex:
resolve: lives: (LiveService) -> LiveService.getAll()
class Home extends Controller constructor: ($scope, $state, Faye, authenticationService, lives)
turns into
['$scope', '$state', 'Faye', 'authenticationService', 'lives' ...]
Try using a factory to represent the lives
resolve function. see below
The Resolver
factory takes in the liveService
and returns all of the lives
.
The resolve.lives
config takes in the Resolver
factory and executes it.
The results will be assigned to the homeController
's last parameter as lives
.
class Resolver extends Factory
constructor: (liveService) ->
return liveService.getAll()
class Routes extends Config
constructor: ($routeProvider) ->
$routeProvider.when '/home',
templateUrl: 'template.html'
controller: 'homeController'
resolve:
lives: ['Resolver', (resolve) -> resolve()]
class Home extends Controller
constructor: ($scope, $state, Faye, authenticationService, lives) ->
# other code
which is equivalent to:
class Resolver
constructor: (liveService) ->
return liveService.getAll()
class Routes
constructor: ($routeProvider) ->
$routeProvider.when '/home',
templateUrl: 'template.html'
controller: 'homeController'
resolve:
lives: ['Resolver', (resolve) -> resolve()]
class Home
constructor: ($scope, $state, Faye, authenticationService, lives) ->
# other code
angular.module('app')
.factory('Resolver', ['liveService', Resolver])
.config(['$routeProvider', Routes])
.controller('homeController', ['$scope', '$state', 'Faye', 'authenticationService', 'lives', Home])
Please let me know if this helps. I follow this pattern myself.
Thanks, Cary
Angular will resolve lives
properly.
Thank you very much! i will try this later, if it works.. can i have your permission to make a blog post? im still building my personal blog.
Greets!
2015-03-26 0:12 GMT-03:00 Cary Landholt [email protected]:
Try using a factory to represent the lives resolve function. see below The Resolver factory takes in the liveService and returns all of the lives . The resolve.lives config takes in the Resolver factory and executes it. The results will be assigned to the homeController's last parameter as lives.
class Resolver extends Factory constructor: (liveService) -> return liveService.getAll() class Routes extends Config constructor: ($routeProvider) -> $routeProvider.when '/home', templateUrl: 'template.html' controller: 'homeController' resolve: lives: ['Resolver', (resolve) -> resolve()] class Home extends Controller constructor: ($scope, $state, Faye, authenticationService, lives) -> # other code
which is equivalent to:
class Resolver constructor: (liveService) -> return liveService.getAll() class Routes constructor: ($routeProvider) -> $routeProvider.when '/home', templateUrl: 'template.html' controller: 'homeController' resolve: lives: ['Resolver', (resolve) -> resolve()] class Home constructor: ($scope, $state, Faye, authenticationService, lives) -> # other code
angular.module('app') .factory('Resolver', ['liveService', Resolver]) .config(['$routeProvider', Routes]) .controller('homeController', ['$scope', '$state', 'Faye', 'authenticationService', 'lives', Home])
Please let me know if this helps. I follow this pattern myself.
Thanks, Cary
— Reply to this email directly or view it on GitHub https://github.com/CaryLandholt/ng-classify/issues/34#issuecomment-86319915 .
Of course
On Thu, Mar 26, 2015 at 1:37 PM, Victor Nahuel Chaves [email protected] wrote:
Thank you very much! i will try this later, if it works.. can i have your permission to make a blog post? im still building my personal blog. Greets! 2015-03-26 0:12 GMT-03:00 Cary Landholt [email protected]:
Try using a factory to represent the lives resolve function. see below The Resolver factory takes in the liveService and returns all of the lives . The resolve.lives config takes in the Resolver factory and executes it. The results will be assigned to the homeController's last parameter as lives.
class Resolver extends Factory constructor: (liveService) -> return liveService.getAll() class Routes extends Config constructor: ($routeProvider) -> $routeProvider.when '/home', templateUrl: 'template.html' controller: 'homeController' resolve: lives: ['Resolver', (resolve) -> resolve()] class Home extends Controller constructor: ($scope, $state, Faye, authenticationService, lives) -> # other code
which is equivalent to:
class Resolver constructor: (liveService) -> return liveService.getAll() class Routes constructor: ($routeProvider) -> $routeProvider.when '/home', templateUrl: 'template.html' controller: 'homeController' resolve: lives: ['Resolver', (resolve) -> resolve()] class Home constructor: ($scope, $state, Faye, authenticationService, lives) -> # other code
angular.module('app') .factory('Resolver', ['liveService', Resolver]) .config(['$routeProvider', Routes]) .controller('homeController', ['$scope', '$state', 'Faye', 'authenticationService', 'lives', Home])
Please let me know if this helps. I follow this pattern myself.
Thanks, Cary
— Reply to this email directly or view it on GitHub https://github.com/CaryLandholt/ng-classify/issues/34#issuecomment-86319915 .
Reply to this email directly or view it on GitHub: https://github.com/CaryLandholt/ng-classify/issues/34#issuecomment-86661943
im sorry but i'm having troubles with annotations .. im including ng-classify in linemanjs.. you script annotates dependencies?
if i leave the annotation of the "lives" parameter.. the app fails.. but if i remove only the annotation it works.. is there a way to get it working? dont know if removing the annotation is safe for minification
Can you share your repo? I'll take a look.
On Mar 26, 2015, at 21:57, Victor Nahuel Chaves [email protected] wrote:
if i leave the annotation of the "lives" parameter.. the app fails.. but if i remove only the annotation it works.. is there a way to get it working? dont know if removing the annotation is safe for minification
— Reply to this email directly or view it on GitHub.
Sadly our repo is private.. but ill share some gists so you can see whats going on:
https://gist.github.com/nahue/2e03b12f909629006c79 is the resolver.. router and controller
https://gist.github.com/nahue/ba2767bfc4302731a77a is the controller result
https://gist.github.com/nahue/79314c5f7a807009d87c is the javascript result of the controller
if remove the "lives" annotation on the last file.. the app works
My gosh, @nahue! My sincere apologies for the extreme delay in replying to your question. I've been focusing on my day job, a startup.
I just realized that I've tested using the angular router; however, ui-router supports resolve in the same way (https://github.com/angular-ui/ui-router/wiki#resolve).
I'm sure you've moved on, but if you haven't, we can setup a screenshare to work through it.
Again, my apologies for the unforgivable delay. :(
Thanks, Cary