3

Here when i click on cartDetails the dynamic scope variable x.SmId value need to be passed to the bellow function and in alert box need to display the parameter .How can we do this one in angular js?

<div ng-app="" ng-controller="MyCtrl">
     <div ng-repeat="x in names">
       <div ng-click="cartDetails('{{x.SmId}}')">
        <div>{{x.name}}</div>
       </div>
     </div>
    </div>

<script>
 angular.module('MyApp', [])
.controller('MyCtrl', ['$scope', '$http', function($scope, $http) {
  $scope.search = function(param) {

      $http.get('AngularJs-Response.jsp?mid='+param).success(function(response) {
        $scope.names = response;        
      });

  };
  $scope.cartDetails = function(smid) {
      alert(smid);
      };
}]);
</script>
1
  • 6
    ..ng-click="cartDetails(x.SmId)"> Commented Feb 16, 2015 at 9:11

2 Answers 2

9

Use simple:-

 ng-click="cartDetails(x.SmId)"
Sign up to request clarification or add additional context in comments.

2 Comments

How to pass single variable that is declared in controller without using x. ?
why don't you validate as answer if it solved your problem?
3

I tried to use:

ng-click="cartDetails(x.SmId)"

but it simply x.SmId as string, its not replaced by value. After reading few more articles, I found a solution like below:

<div ng-click="cartDetails('{{x.SmId}}')">

Its a working solution in AngularJS v1.3.9

1 Comment

And if you want the x.SmId as a boolean? What should we do? Because 'false' equals true. Any ideas?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.