angularjs - Passing parameters to the route on button click -


i new angularjs. have search box button hits route defined in config of angular application.

<div class="search-block clearfix">   <div class="input-group">     <input type="text" placeholder="search here..."  class="form-control input-sm">     <div class="input-group-btn">       <button type="button" class="btn btn-default btn-sm" go-click="search.htm">search</button>     </div><!-- /btn-group -->   </div><!-- /input-group --> </div> 

adding code snippet of route config:

myapp.config(function ($routeprovider){   $routeprovider.     .when('/search.htm',      {         controller:'controllers.searchctrl',         templateurl:'/partials/search/searchpage.html'      })     .otherwise({ redirectto: '/' });    .... 

adding directive(go-click) code well:

    myapp.directive( 'goclick', function ( $location ) {       return function ( scope, element, attrs ) {         var path;         attrs.$observe( 'goclick', function (val) {         path = val;       });        element.bind( 'click', function () {          scope.$apply( function () {           $location.path( path );       });     });   }; }); 

you can use $route , $routeparams services pass parameters new route.

if change route to:

.when('/search.htm/:paramname',      {         controller:'controllers.searchctrl',         templateurl:'/partials/search/searchpage.html'      }) 

and redirect search.htm/someparam

then parameter someparam available in route's controller service $routeparams (which object containing parameters) or in $route service under $route.current.params (which same object).

this covered in docs.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -