I am not familiar with the sample you mentioned and I hope that my answer wont be trivial.
In general once the DOM element binds to the model (ng-model for example) every change that you will do to the model will be updated without the need for you to “do something”, its internals of angular and I am not sure that if I will go there it will help you.
So if you have a array of items, and you push another item to this array, your model will be updated which will trigger a DOM change as well.so if you iterate through the items by using ng-repeat it will be reflected once the change is applied.
now, regarding synchronizing between views, you can create a service that holds your state and inject it between controllers, it is not recommended to use the $rootScope / $scope.
Hope that my answer helps
Got it.
so here is my suggestion.
Yes, you need to add the “Add” function, means add a “+” or and “Add” button at the upper bar which will open a Modal View (use the $ionicModal) and in this Modal just add the functionality of naming the playlist and more cool stuff if you want.
If you want much more simple approach, you can use $IonicPopup and pop a prompt with a text box to enter the playlist name.
once you have the playlist name in you hand, add it to the $scope.Playlists array and you are ready to go.
Tell me if it worked for you.
I wanted it go to child of parent. Like when you click on the parent the child page is shown in the view.
So, when I want to add item, the URL routing should take me to child page. but only that there no
data in the view.
I changed href to href="#/app/playlists/{{playlists.length}}+1" for add button.
The problem is the index value of parent list is not the same as ‘id’ value of child. The 'id’
values may change if new person is added or deleted. In UI router, :playlistID is not the ‘id’ is JSON
array.
Sorry, I think I lost your business flow. If you want to add another title to the playlists by routing to another view, just add another state (add-playlist-title for ex.) and in this view add the UI and behavior so once a new title is added the Playlists Array is being incremented by one push(‘title’:whatever, ‘id’:playlists.length); only then the routing for playlist.length will go somewhere. (BTW, if you have an array of 4 items and you are doing playlists.length+1 it will add it to the 6th place not the 5th).
Of course that you need to handle persistence and all this stuff for a real application and not use the sample for keeping the playlists.
So, if localStorage(PlayListCreated) value is number of playlists say 12 – total entered.
And 5 where deleted. The index would be ‘7’ (ok, 6)…
On the next add of playlist, the playlist id should be 13, and the index would be “8” (ok,7).
Then I would set the new playlist value to be localStorage(PlayListCreated) plus 1
I understanding the logic.
No. BTW, why do you need all this complex ID calculations ?
Let me ask you this, from business perspective Id mainly represents something, what is the meaning of the Id in your case ?
IMHO In case of a playlists, it is meaningless.
you can add an Id just to simplify the way you query or keep track on the information (entity relationship) but in your case I think you dont need it. just create a new GUID for every title you add. {‘title’:some new title, ‘id’:someGuid} if you want to know the total number of playlists just call the Array length property and that’s pretty much it.
I am trying to approach your problem from the business side and not from the technical side. this will probably break the loop of trying to find the right way to synchronize the id.
Make sense ?