0

I am new in angularjs. This may be basic for you guys. Actually, after filling the form, the submit button must create a new link. The problem that i'm using

document.getElementById('myP').appendChild(newLink);

and it create a link after filling the form.But when i refresh the page it disappear. When i refresh or load the page it must contain all the links that i have created before. Is there a method that maintain my links?

Poul Kruijt
  • 69,713
  • 12
  • 145
  • 149
GEmyy
  • 1
  • 1
  • 8
  • Where do you store the link now? Local `$scope`? – senschen Mar 31 '16 at 11:46
  • Here is my code:

    Un peu de texte et un lien

    and this is my controller: var newLink = document.createElement('a'); var newLinkText = document.createTextNode("Mon site"); newLink.id = 'sdz_link'; newLink.href = 'http://www.siteduzero.com'; newLink.title = 'Découvrez le Site du Zéro !'; newLink.setAttribute('tabindex', '10'); newLink.appendChild(newLinkText); document.getElementById('myP').appendChild(newLink);
    – GEmyy Mar 31 '16 at 13:06

2 Answers2

0

Try this on submit button:

$state.go('.', null, {reload:true});

This will reload your page on same state
use angular Js to save your data or to submit data

$scope.variable = {};
$scope.save = function (object) {
   Service.save(object, function () {
      $state.go('.', null, {'reload': true});
   });
};
ojus kulkarni
  • 1,877
  • 3
  • 25
  • 41
0

You'll need to store your link somewhere other than just on the page if you need it to persist. There are a couple of options for that, which this answer explains, but my suggestion is to use localStorage to hold the list of links.

Community
  • 1
  • 1
senschen
  • 794
  • 10
  • 27
  • But after that i need that my code generate buttons every time i clic on the sabmit button. And the id and name of this new button will be the id and the name witch are added in the form. So does this sollution still working with this? And if so, how can i store my buttons? – GEmyy Mar 31 '16 at 13:23
  • It should. You'll have to do some research to determine *how* best to store your data (an array of objects with properties for the link, id, and name of the button is where I would start), but localStorage is definitely a good *where* to store it. – senschen Mar 31 '16 at 13:27
  • thnx a lot @senschen i will try it this way. If you have good documentation it'll be cool. – GEmyy Mar 31 '16 at 13:57