Helloo, i trying save data from my Add new phone Form into array uses factory in AngularJS. is my Home.html file:
<div class="popup" dx-popup="popupOptions">
<div class="dx-label">Phone Name</div>
<div dx-text-box="nameOfPhone" ng-model="phoneName"></div><br /><br />
<div class="dx-label">Phone Seria</div>
<div dx-text-box="seriaOfPhone" ng-model="phoneSeria"></div><br /><br />
<div class="dx-label">Image Url</div>
<div dx-text-box="imgurlOfPhone" ng-model="phoneImgUrl"></div><br />
<img src="{{phoneImgUrl}}" alt="Image" style="max-height:20%;max-width:20%" />
<div dx-button="savePhone"></div>
<div dx-button="cancelSavePhone"></div>
</div>
for saving data i use factory in my HomeController.js i writed code:
var myApp = angular.module("myApp", ['dx']);
myApp.controller("defaultCtrl", ['$scope', 'notify', function ($scope, notify) {
$scope.savePhone = {
text: "Save",
type: "success",
onClick: function () {
var phoneTest = $scope.phoneName + $scope.phoneSeria + $scope.phoneImgUrl;
notify(phoneTest);
}
}
//factory session phones storage
}]).factory('notify',['$window', function ($scope) {
$scope.phonesStorage = [{}];
return function (phoneTest) {
$scope.phonesStorage.push(phoneTest);
alert($scope.phonesStorage);
};
}]);
For checking myself, i use alert($scope.phonesStorage);
it works, data copies in to array, but, when i'm trying display data in my Home.html page use ng-repeat happened nothing:
<div ng-repeat="phone in phonesStorage">
{{phone}}
</div>
how i should save data for displaying, i tryed save data in style like this
var phoneTest = '{'+$scope.phoneName + $scope.phoneSeria + $scope.phoneImgUrl + '}';
and like this:
var phoneTest = '{'+'"Name"' + ':' + '"' + $scope.phoneName + '",' + '"Seria"' + ':' + '"' + $scope.phoneSeria + '",' + '"ImgUrl"' + ':' + '"' + $scope.phoneImgUrl + '"}'; ?
Thanks for your answers.
