angularjs - How to send data from Html File To another one Using angular? -
i try sample project take data in form in html file .. pass spring service .. return object .. want pass object html fie display
form's html file :
<!doctype html> <html ng-app="phase2"> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> <head> <title>sign page</title> <script src="rigesterationcontroller.js"></script> </head> <body > <center> <p>enter user name : <input type="text" , name="username" id ="uname" required /> </p> <p>enter email : <input type="text" , name="email" id ="email" required /> </p> <p>enter password : <input type="password" , name="pass" id ="pass" required/> </p> <p>choose gender : <br> male<input type="radio" name="gender" value="m" id="gender" /> female<input type="radio" name="gender" value="f" id="gender"/> </p> <p>choose user type :<br> student<input type="radio" name="usertype" value="s" id="utype" /> teacher<input type="radio" name="usertype" value="t" id="utype"/> </p> <div ng-controller="signup"> <input type="button" name="signup" value="signup" ng-click="save()" /> </div> </center> </body> </html>
rigesterationcontroller.js file :
angular.module("phase2" , []) .controller("signup" , function($scope , $http ) { var dat ; $scope.save = function() { var email= document.getelementbyid("email").value; var uname=document.getelementbyid("uname").value; var pass=document.getelementbyid("pass").value; var gender=document.getelementbyid("gender").value; var usertype=document.getelementbyid("utype").value; var info ; $http.get('http://localhost:8090/signup/'+email+'/'+uname+'/'+pass+'/'+gender+'/'+usertype) .then(function(response) { info = response.data; dat=info ; alert(dat.name) ; window.location.href="http://localhost:8060/theangular_project/studentpage.html"; }); } });
second html file :
<!doctype html> <html ng-app="phase2"> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> <script src="rigesterationcontroller.js"></script> <head> <title>student page</title> </head> <body> <div ng-controller="signup"> <p><span class="name">welcome {{dat.name}}</p> </div> </body> </html>
now nothing appeared in dat.name in second html file .. although .. in regestrationcontroller.js ..i test dat.name in allert , appeared successfuly .. in advance
i found answer wawy in post.. [angularjs - passing data between pages
you need create service able share data between controllers.
app.factory('myservice', function() { var saveddata = {} function set(data) { saveddata = data; } function get() { return saveddata; } return { set: set, get: } });
in controller a:
myservice.set(yourshareddata);
in controller b:
$scope.desiredlocation = myservice.get();
remember inject myservice in controllers passing parameter.
Comments
Post a Comment