问题描述:

I'm trying to create an app with 2 states using ui-route, here is the configState:

angular.module('app',

[

'ui-notification',

'ngSanitize',

'ui.select',

'ui.router'

]

).config([

'$stateProvider',

'$urlRouterProvider',

function($stateProvider, $urlRouterProvider){

$urlRouterProvider.otherwise("/")

$stateProvider

.state('recipes', {

url: "/",

templateUrl: "pages/recipes.html"

})

.state('newRecipe', {

url: "/newRecipe",

templateUrl: "pages/recipe.template.html",

resolve: {

Notification: 'Notification',

BeerRecipes: 'BeerRecipes'

},

controller:"beerRecipeCtrl"

})

}]);

As you can see, each state has his template. The second state has a controller that depends of two services: Notification and BeerRecipes. Notification is a third party service and BeerRecipes is a custom service.

angular.module('app')

.factory('BeerRecipes',function(){

var recipes = [],

var beerRecipes = {

getRecipes: function(){

return recipes;

},

addRecipe: function(recipe){

var id = recipes.length + 1;

recipe.id = id;

recipes.push(recipe);

},

getRecipeById: function(id){

return recipes[id];

}

};

return beerRecipes;

});

This code doesn't work, it seems that the problem is that the service BeerRecipe is not being injected in the controller, but I don't know how to solve it.

I will appreciate any help or suggestions.

Thank you!!

相关阅读:
Top