i'm trying send 2 parameters first.html
second.html
through url , value in second.html
using routeparams
. have set base tag <base href="file:///d:/abhilash/node/angapp/"/>
, on click of button parameters in input textboxes should passed through url.
the first.html:
<!doctype html> <html ng-app="myapp"> <head> <title></title> <base href="file:///d:/abhilash/node/angapp/"/> </head> <body> <script type="text/javascript" src="angular.js"></script> <script type="text/javascript" src="angular-route.js"></script> <script type="text/javascript" src="controller.js"></script> <div ng-controller="firstcontroller"> first name:<input type="text" ng-model="firstname"><br> last name:<input type="" ng-model="lastname"><br> <input type="button" ng-click="loadview()" value="submit" name=""> </div> </body> </html>
second.html:
<!doctype html> <html ng-app="myapp"> <head> <title></title> <base href="file:///d:/abhilash/node/angapp/"/> </head> <body> <script type="text/javascript" src="angular.js"></script> <script type="text/javascript" src="angular-route.js"></script> <script type="text/javascript" src="controller.js"></script> <div ng-controller="secondcontroller"> {{firstname}} </div> </body> </html>
this controller:
(function(){ var app = angular.module('myapp', ['ngroute']); app.config(function($routeprovider,$locationprovider){ $routeprovider.when('/first',{ templateurl:'/first.html', controller: 'firstcontroller' }) .when('/second/:firstname/:lastname',{ templateurl:'/second.html', controller:'secondcontroller' }) .otherwise({ redirectto:'/first' }) $locationprovider.html5mode(true); }) app.controller('firstcontroller',function($scope,$location){ $scope.firstname=""; $scope.lastname=""; $scope.loadview = function() { $location.path('second/'+$scope.firstname +"/" +$scope.lastname); console.log($location.url()); } }) .controller('secondcontroller',function($scope,$routeparams){ $scope.firstname = $routeparams.firstname; $scope.lastname = $routeparams.lastname; }) }());
check code here if deploying app root context (e.g. https://myapp.com/), set base url /:
<head> <base href="/"> ... </head>
if deploying app sub-context (e.g. https://myapp.com/subapp/), set base url url of subcontext:
<head> <base href="/subapp/"> ... </head>
Comments
Post a Comment