ng-repeat not displaying data from localStorage











up vote
0
down vote

favorite












In my Controller:



By clicking on an element, the information is given to tabNameStore.
The data is displayed in html by name



     $scope.openTab = function($event){

//Checks for doubles
if($scope.tabNameStore.length>0){
for(var i=0; i<$scope.tabNameStore.length; i++){
if($scope.tabNameStore[i].id == $event.currentTarget.id){
console.log("Already open");
return;
}
}
}

//Saves name, ID and number
$scope.tabNameStore[count] = ({name: $event.currentTarget.innerHTML,
id: $event.currentTarget.id, num: count++});

//Tries to get item by id
var local = localStorage.getItem($event.currentTarget.id);

//If not stored in local, it does so
if (local == null){
localStorage.setItem($event.currentTarget.innerHTML,
$scope.tabNameStore[count-1].name);
localStorage.setItem($event.currentTarget.id,
$scope.tabNameStore[count-1].id);
console.log("null");
} else{
console.log("not null");
return;
}

}


Save the data from localStorage back in tabNameStore



     $window.onload = function() {       
var archive = ;
archive = allStorage();
count = 0;

for(var i=0; i<archive.length/2; i++){
if(archive[i] != null){
$scope.tabNameStore[count] = ({name: archive[i], id:
archive[i+archive.length/2], num: count++});
}
}
}


Getting all data from localStorage



     function allStorage() {
var keys = Object.keys(localStorage); // Gibt alle Schlüssel zurück
var archive = ;

for (var i=0; i< keys.length; i++) {
archive.push(keys[i]);
}
return archive;
}


The HTML is:



   <article id="default">

<div id="heading">
<a href="###" class="tab" id="desktop" >Desktop</a>
<a href="###" class="tab" id="" data-ng-repeat="y in
tabNameStore" data-ng-click="" >{{y.name}}</a>
</div>

<div class="gridly toggle" id="Desktop">
<div class="brick small" draggable="true" data-letters="
{{x.name[0]}}" id="{{x.id}}" data-ng-repeat="x in storage |
orderBy: '-name'" data-ng-click="openTab($event)">
{{x.name}}
</div>
</div>
</article>


After reloading the page and getting the data from localStorage it's still not displayed, even if the array is filled. Just if I click again on one of my elements (openTab function), all elements stored in localStorage are displayed at once.










share|improve this question
























  • Post your html as well
    – Vicky Gill
    Nov 22 at 7:37










  • @VickyGill Added it.
    – temp
    Nov 22 at 7:45















up vote
0
down vote

favorite












In my Controller:



By clicking on an element, the information is given to tabNameStore.
The data is displayed in html by name



     $scope.openTab = function($event){

//Checks for doubles
if($scope.tabNameStore.length>0){
for(var i=0; i<$scope.tabNameStore.length; i++){
if($scope.tabNameStore[i].id == $event.currentTarget.id){
console.log("Already open");
return;
}
}
}

//Saves name, ID and number
$scope.tabNameStore[count] = ({name: $event.currentTarget.innerHTML,
id: $event.currentTarget.id, num: count++});

//Tries to get item by id
var local = localStorage.getItem($event.currentTarget.id);

//If not stored in local, it does so
if (local == null){
localStorage.setItem($event.currentTarget.innerHTML,
$scope.tabNameStore[count-1].name);
localStorage.setItem($event.currentTarget.id,
$scope.tabNameStore[count-1].id);
console.log("null");
} else{
console.log("not null");
return;
}

}


Save the data from localStorage back in tabNameStore



     $window.onload = function() {       
var archive = ;
archive = allStorage();
count = 0;

for(var i=0; i<archive.length/2; i++){
if(archive[i] != null){
$scope.tabNameStore[count] = ({name: archive[i], id:
archive[i+archive.length/2], num: count++});
}
}
}


Getting all data from localStorage



     function allStorage() {
var keys = Object.keys(localStorage); // Gibt alle Schlüssel zurück
var archive = ;

for (var i=0; i< keys.length; i++) {
archive.push(keys[i]);
}
return archive;
}


The HTML is:



   <article id="default">

<div id="heading">
<a href="###" class="tab" id="desktop" >Desktop</a>
<a href="###" class="tab" id="" data-ng-repeat="y in
tabNameStore" data-ng-click="" >{{y.name}}</a>
</div>

<div class="gridly toggle" id="Desktop">
<div class="brick small" draggable="true" data-letters="
{{x.name[0]}}" id="{{x.id}}" data-ng-repeat="x in storage |
orderBy: '-name'" data-ng-click="openTab($event)">
{{x.name}}
</div>
</div>
</article>


After reloading the page and getting the data from localStorage it's still not displayed, even if the array is filled. Just if I click again on one of my elements (openTab function), all elements stored in localStorage are displayed at once.










share|improve this question
























  • Post your html as well
    – Vicky Gill
    Nov 22 at 7:37










  • @VickyGill Added it.
    – temp
    Nov 22 at 7:45













up vote
0
down vote

favorite









up vote
0
down vote

favorite











In my Controller:



By clicking on an element, the information is given to tabNameStore.
The data is displayed in html by name



     $scope.openTab = function($event){

//Checks for doubles
if($scope.tabNameStore.length>0){
for(var i=0; i<$scope.tabNameStore.length; i++){
if($scope.tabNameStore[i].id == $event.currentTarget.id){
console.log("Already open");
return;
}
}
}

//Saves name, ID and number
$scope.tabNameStore[count] = ({name: $event.currentTarget.innerHTML,
id: $event.currentTarget.id, num: count++});

//Tries to get item by id
var local = localStorage.getItem($event.currentTarget.id);

//If not stored in local, it does so
if (local == null){
localStorage.setItem($event.currentTarget.innerHTML,
$scope.tabNameStore[count-1].name);
localStorage.setItem($event.currentTarget.id,
$scope.tabNameStore[count-1].id);
console.log("null");
} else{
console.log("not null");
return;
}

}


Save the data from localStorage back in tabNameStore



     $window.onload = function() {       
var archive = ;
archive = allStorage();
count = 0;

for(var i=0; i<archive.length/2; i++){
if(archive[i] != null){
$scope.tabNameStore[count] = ({name: archive[i], id:
archive[i+archive.length/2], num: count++});
}
}
}


Getting all data from localStorage



     function allStorage() {
var keys = Object.keys(localStorage); // Gibt alle Schlüssel zurück
var archive = ;

for (var i=0; i< keys.length; i++) {
archive.push(keys[i]);
}
return archive;
}


The HTML is:



   <article id="default">

<div id="heading">
<a href="###" class="tab" id="desktop" >Desktop</a>
<a href="###" class="tab" id="" data-ng-repeat="y in
tabNameStore" data-ng-click="" >{{y.name}}</a>
</div>

<div class="gridly toggle" id="Desktop">
<div class="brick small" draggable="true" data-letters="
{{x.name[0]}}" id="{{x.id}}" data-ng-repeat="x in storage |
orderBy: '-name'" data-ng-click="openTab($event)">
{{x.name}}
</div>
</div>
</article>


After reloading the page and getting the data from localStorage it's still not displayed, even if the array is filled. Just if I click again on one of my elements (openTab function), all elements stored in localStorage are displayed at once.










share|improve this question















In my Controller:



By clicking on an element, the information is given to tabNameStore.
The data is displayed in html by name



     $scope.openTab = function($event){

//Checks for doubles
if($scope.tabNameStore.length>0){
for(var i=0; i<$scope.tabNameStore.length; i++){
if($scope.tabNameStore[i].id == $event.currentTarget.id){
console.log("Already open");
return;
}
}
}

//Saves name, ID and number
$scope.tabNameStore[count] = ({name: $event.currentTarget.innerHTML,
id: $event.currentTarget.id, num: count++});

//Tries to get item by id
var local = localStorage.getItem($event.currentTarget.id);

//If not stored in local, it does so
if (local == null){
localStorage.setItem($event.currentTarget.innerHTML,
$scope.tabNameStore[count-1].name);
localStorage.setItem($event.currentTarget.id,
$scope.tabNameStore[count-1].id);
console.log("null");
} else{
console.log("not null");
return;
}

}


Save the data from localStorage back in tabNameStore



     $window.onload = function() {       
var archive = ;
archive = allStorage();
count = 0;

for(var i=0; i<archive.length/2; i++){
if(archive[i] != null){
$scope.tabNameStore[count] = ({name: archive[i], id:
archive[i+archive.length/2], num: count++});
}
}
}


Getting all data from localStorage



     function allStorage() {
var keys = Object.keys(localStorage); // Gibt alle Schlüssel zurück
var archive = ;

for (var i=0; i< keys.length; i++) {
archive.push(keys[i]);
}
return archive;
}


The HTML is:



   <article id="default">

<div id="heading">
<a href="###" class="tab" id="desktop" >Desktop</a>
<a href="###" class="tab" id="" data-ng-repeat="y in
tabNameStore" data-ng-click="" >{{y.name}}</a>
</div>

<div class="gridly toggle" id="Desktop">
<div class="brick small" draggable="true" data-letters="
{{x.name[0]}}" id="{{x.id}}" data-ng-repeat="x in storage |
orderBy: '-name'" data-ng-click="openTab($event)">
{{x.name}}
</div>
</div>
</article>


After reloading the page and getting the data from localStorage it's still not displayed, even if the array is filled. Just if I click again on one of my elements (openTab function), all elements stored in localStorage are displayed at once.







angularjs






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 at 7:44

























asked Nov 22 at 7:36









temp

1138




1138












  • Post your html as well
    – Vicky Gill
    Nov 22 at 7:37










  • @VickyGill Added it.
    – temp
    Nov 22 at 7:45


















  • Post your html as well
    – Vicky Gill
    Nov 22 at 7:37










  • @VickyGill Added it.
    – temp
    Nov 22 at 7:45
















Post your html as well
– Vicky Gill
Nov 22 at 7:37




Post your html as well
– Vicky Gill
Nov 22 at 7:37












@VickyGill Added it.
– temp
Nov 22 at 7:45




@VickyGill Added it.
– temp
Nov 22 at 7:45












1 Answer
1






active

oldest

votes

















up vote
0
down vote













I solved it:



By adding a $scope.$apply around the part that reloads the array:



     ....
$scope.$apply(function(){
for(var i=0; i<archive.length/2; i++){
if(archive[i] != null){
$scope.tabNameStore[count] = ({name: archive[i], id:
archive[i+archive.length/2], num: count++});
}
}
});
....


Like this the updated array is set up for angularjs after reloading.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53425957%2fng-repeat-not-displaying-data-from-localstorage%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    I solved it:



    By adding a $scope.$apply around the part that reloads the array:



         ....
    $scope.$apply(function(){
    for(var i=0; i<archive.length/2; i++){
    if(archive[i] != null){
    $scope.tabNameStore[count] = ({name: archive[i], id:
    archive[i+archive.length/2], num: count++});
    }
    }
    });
    ....


    Like this the updated array is set up for angularjs after reloading.






    share|improve this answer

























      up vote
      0
      down vote













      I solved it:



      By adding a $scope.$apply around the part that reloads the array:



           ....
      $scope.$apply(function(){
      for(var i=0; i<archive.length/2; i++){
      if(archive[i] != null){
      $scope.tabNameStore[count] = ({name: archive[i], id:
      archive[i+archive.length/2], num: count++});
      }
      }
      });
      ....


      Like this the updated array is set up for angularjs after reloading.






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        I solved it:



        By adding a $scope.$apply around the part that reloads the array:



             ....
        $scope.$apply(function(){
        for(var i=0; i<archive.length/2; i++){
        if(archive[i] != null){
        $scope.tabNameStore[count] = ({name: archive[i], id:
        archive[i+archive.length/2], num: count++});
        }
        }
        });
        ....


        Like this the updated array is set up for angularjs after reloading.






        share|improve this answer












        I solved it:



        By adding a $scope.$apply around the part that reloads the array:



             ....
        $scope.$apply(function(){
        for(var i=0; i<archive.length/2; i++){
        if(archive[i] != null){
        $scope.tabNameStore[count] = ({name: archive[i], id:
        archive[i+archive.length/2], num: count++});
        }
        }
        });
        ....


        Like this the updated array is set up for angularjs after reloading.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 22 at 8:57









        temp

        1138




        1138






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53425957%2fng-repeat-not-displaying-data-from-localstorage%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Sphinx de Gizeh

            Dijon

            Get global maximum slope