/**
 * Created by sylflo on 11/15/15.
 */

(function () {

  'use strict';

  angular.module('NourritureControllers')
    .controller('ParametersIngredientsUserProfileController', ParametersIngredientsUserProfileController);

  ParametersIngredientsUserProfileController.$inject = ["$scope", "IngredientService", 'TagsService', 'toastr', "$log", "$mdDialog", "$document"];

  function ParametersIngredientsUserProfileController($scope, IngredientService, TagsService, toastr, $log, $mdDialog, $document) {

    var vm = this;

    $log.log("innit");

    //Vars for Chips
    vm.names_ingredient = [];
    vm.selectedItemChip = null;
    vm.searchTextChip = null;
    vm.itemsAutocomplete = [];


    //Chips functions
    vm.transformChip = function (chip) {
      if (angular.isObject(chip))
        return chip;
      if (angular.isUndefined(chip._id))
        return {
          name: chip
        };
      else
        return {
          name: chip.name
        }
    };

    vm.getNameIngredients = function (name) {
      $log.log("innit");
      return (IngredientService
        .ingredient_name
        .query({name: name})
        .$promise
        .then(vm.TagsGetNameSuccess, vm.TagsGetNameFailure));

      /* return (TagsService
       .tags_name
       .query({name: name})
       .$promise
       .then(vm.TagsGetNameSuccess, vm.TagsGetNameFailure));*/
    }


  }

})();

@@ -1154,35 +1154,42 @@
        .then(vm.
-Tag
+Ingredient
 sGetNameSuccess,
@@ -1184,35 +1184,42 @@
 NameSuccess, vm.
-Tag
+Ingredient
 sGetNameFailure)
@@ -1230,164 +1230,323 @@
     
-  /* return (TagsService%0A       .tags_name%0A       .query(%7Bname: name%7D)%0A       .$promise%0A       .then(vm.TagsGetNameSuccess, vm.TagsGetNameFailure));*/
+%7D;%0A%0A    vm.IngredientsGetNameFailure = function (data) %7B%0A      $log.log(data.data);%0A      vm.itemsAutocomplete = %5B%5D;%0A      return (vm.itemsAutocomplete);%0A    %7D;%0A%0A    vm.IngredientsGetNameSuccess = function (data) %7B%0A      $log.log(data);%0A      vm.itemsAutocomplete = data;%0A      return (vm.itemsAutocomplete);
 %0A    %7D
+;
 %0A%0A%0A 

add promise function for getNameIngredient