Nahiduzzaman Rose Nahiduzzaman Rose - 1 year ago 80
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
it gets the value of
correctly, but when i am sending this using
it is getting no value at all! The alert is just saying

Any Idea? why this is happening?

Answer Source

Try this,

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

app.controller('MainCtrl', function($scope,$location) {
$scope.topHeading = "test";  
$scope.go = function(path){
<script src=""></script>

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download