angularjs - How to bind a value from a model to URL? -


i created 2 inputs:

<input type="text" ng-model="x"> <input type="text" ng-model="y"> 

and want bind values models url via $routeprovider or $routeparams or else. url change automatically. example: site.com#/x/y. on contrary if request url like: site.com#/2/4 values url input in models. how bind this?

you can use $routeprovider achieve same

in app.js config method below

var myapp = angular.module('myapp',['ngroute']); myapp.config(['$routeprovider', function($routeprovider){ $routeprovider.    when('/details/:itemid, {    templateurl: 'partial.html',    controller:'detailscontroller'    }) ]);  myapp.controller('detailscontroller', ['$scope','$routeparams',  function detailscontroller($scope,$routeparams){ //the model retrieved url in below line var modelretrieved = $routeparams.itemid;   }]); 

use below code in html

<html> <head> <!-- include angular libraries , app.js --> </head> <body ng-app = "myapp"> <!-- binding model --> <input type="text" ng-model="x"> <!-- passing model link --> <a href "/details/{{x}}"></a> </body> </html> 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -