当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Service is not injected in a controller view when I use ui-route

问题描述:

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!!

分享给朋友:
您可能感兴趣的文章:
随机阅读: