I'd like to use the .replace("'", r"\'")
method to avoid problems caused by single quotes within JSON strings.. and so that my factory works ...as intended
Simplest solution I could find from This post suggests the replace
method, however, beeing new in JS, I have troubles implementing it within my factory.
I am not quite sure where and how to put it, so that any given controller calling different function (especially the getDishes
and getDish
functions at the end of the script below) all get a "formatted string"
Factory :
angular.module('wmapp.factory_dishes', [])
.factory('dishesFactory', function (){
var factory = {
dishes :[
{ nameEnglish: 'beef burgungdy',
nameLocal: 'boeuf bourgignon',
description: 'xxxxxx',
region: 'sicile',
itemid: 'IT018',
cuisineTypeIsoCode: 'IT',
country:'France',
dishCategory: 'Meat',
},
{ nameEnglish: 'duck liver',
nameLocal: 'foie gras',
description: 'xxxxxx',
region: 'sicile',
itemid: 'IT021',
cuisineTypeIsoCode: 'IT',
country:'France',
dishCategory: 'fruit',
},
{ nameEnglish: 'veal stew',
nameLocal: 'blanquette de veau',
description: 'xxxxxx',
region: 'parme',
itemid: 'IT023',
cuisineTypeIsoCode: 'IT',
country:'France',
dishCategory: 'fruit',
},
{ nameEnglish: 'onion soup',
nameLocal: 'soxxxxxx',
region: 'vanitia',
itemid: 'IT022',
cuisineTypeIsoCode: 'IT',
imageSource: '( "img/" + dish.cuisineTypeIsoCode + "/" + dish.itemid + "small.jpg")',
country:'France',
dishCategory: 'Soup',
},
{ nameEnglish: 'TAPENADE',
nameLocal: 'Tapenade',
description: 'xxxxxx',
region: 'Provence-Alpes-Côte d'Azur',
regioncode: 'FR.B8',
itemid: 'FR002',
cuisineTypeIsoCode: 'FR',
dishCategory: 'Entrée / Appetizers',
country: 'France'}
],
getDishes : function (){
return factory.dishes;
},
getDish :function (itemid){
var dish = {};
angular.forEach(factory.dishes, function(value, key) {
if (value.itemid == itemid){
dish = value
}
});
return dish;
}
}
return factory;
})