angularjs - Communication between controllers through $window.location.href -
i have following statements in controller 1:
$scope.field1 = "abcd"; $window.location.href = 'main.html';
then, in main.html
have controller 2, , need have access value of field1.
is possible using service or factory, $window.location.href
replace scope? $broadcast/$emit work in case?
update
i tried singleton service calling set
in controller 1 , get
in controller 2, variable in controller 2 still null
app.service('singleton', function() { var myfield1 = null; this.set = function(f) { myfield1 = f; }; this.get = function() { return myfield1; };
if have 2 different pages, like:
<html> page1 </html> <html> page2 </html>
then independent, i.e. angular loaded separately in page1 , page2 - can not make javascript connection between them. js objects discarded when change url. can use param page1.html?param=value, cookies, localstorage (2 latest same domain).
thats why angular apps 1 page - may see different paths in url, still 1 page (i.e. index.html). in case can connect them using angular service, $rootscope (which service too) or using params in ui-router.
Comments
Post a Comment