0

Helloo, i created simple AngularJS application, i have two buttons(Create New Phone and Create New Category), i saved my categories into array use factory:

myApp.factory('categoriesStorage', function () {
    var storage = [];
    var categories = ["Apple","HTC"];

    storage.addCategory = function (categoryTest) {
        categories.push(categoryTest);
        console.log(categories);
    }

    storage.getCategories = function()
    {
        return categories;
    }

    return storage;
});

enter image description here

At Add New Phone form i have dx-select-box -element:

<div class="dx-label">Phone Name</div>
               <div dx-select-box="nameOfPhone" ng-model="phoneName"></div><br/><br />

For Getting elements from array i use the next code in my HomeController.js //name of phone select-box pop-up

  $scope.nameOfPhone = {
        items: categoriesStorage.getCategories()

    };

It worksenter image description here

till when i change focus or close Add New Category form, new elements adds into array but don't displaying into select-box.

Thanks for your answers!

Uladz Kha
  • 2,154
  • 4
  • 40
  • 61
  • Is there common controller between view adding category & phone? – Dhiren Mar 09 '16 at 15:17
  • Yes, one controller, two factories https://github.com/Ubuntus/DevExtremeAngularJSChartsTest/blob/master/DevExtremeAngularJSChartsTest/Controllers/Exercise/HomeController.js – Uladz Kha Mar 09 '16 at 15:20

1 Answers1

0

You need to call this line again when Add phone view is displayed.

$scope.nameOfPhone = {
    items: categoriesStorage.getCategories()
};
Dhiren
  • 592
  • 5
  • 16
  • i done like this: *$scope.nameOfPhone.items = phonesAndCategoriesStorages.getCategories();* - nothing( may be do you have another ideas? source code of my app you can find https://github.com/Ubuntus/DevExtremeAngularJSChartsTest/blob/master/DevExtremeAngularJSChartsTest/Controllers/Exercise/HomeController.js – Uladz Kha Mar 10 '16 at 06:27
  • Not able to find proper view of the controller. Also, there is no other solution unless you store data on controller array of categories instead of saving to service since you have same controller. So whenever you update categories, controllers will have latest categories. If above solution has solved your problem, please mark it as answer. – Dhiren Mar 10 '16 at 09:41