Nahiduzzaman Rose Nahiduzzaman Rose - 4 months ago 15
AngularJS Question

Why ng-click is unable to send function parameter which is embraced with angular {{ }} brackets?

I want to send a path by calling a function, by sending the path as function parameter.

However my controller code:

$scope.go = function(path){
alert(path); //show the path comes in as parameter
$location.path( path );
}


My view code (.html)

<button ng-click="go('/hotellist/{{topHeading}}?tab=packages')" ></button>


I have checked
{{topheading}}
it gets the value of
$scope.topheading
correctly, but when i am sending this using
ng-click
it is getting no value at all! The alert is just saying
'/hotelist/?tab=packages'
.

Any Idea? why this is happening?

Answer

Try this,

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope,$location) {
$scope.topHeading = "test";  
$scope.go = function(path){
    console.log(path);
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>


 <body ng-app="plunker" ng-controller="MainCtrl">
   <button ng-click="go('/hotellist/'+topHeading+'?tab=packages')">GO</button>
    
  </body>