2

I have a controller, in which I start an http request and once the request is completed, I call another view and then used ng-click.But My ng-click is not working .

here is my code.

app.controller('listuser', function ($scope,$http,$log,$window) {
        $scope.userdetail = {};
        return $http({
                 method: 'POST',
                 url: 'apisource.php',

            })
            .then(function (results) {

                $scope.data=results.data;
                return $scope.data;
            });

         $scope.douserdetail = function(user) {
             alert('test');
        };

    });
<tr data-ng-repeat="x in data">
    <td>
        <input type="hidden"  name="id" ng-model="userdetail.id" value="{{x.id}}" />
        <a href='' ng-click="douserdetail(userdetail)" class="user-link">{{x.First_Name}}{{x.Last_time}}</a>
        <span class="user-subhead">{{x.Phd_University}}</span>
    </td>
</tr>
jnthnjns
  • 8,962
  • 4
  • 42
  • 65

2 Answers2

2

Your code has a return in the controller on line 3 of what you are showing so no code beyond the return statement is executing, try this:

app.controller('listuser', function ($scope,$http,$log,$window) {
    $scope.userdetail = {};
    $scope.data = [];

    var init = function () {
        $http({
            method: 'POST',
            url: 'apisource.php',

        })
            .then(function (results) {
                $scope.data=results.data;
            });
    };
    init();

    $scope.douserdetail = function(user) {
        alert('test');
    };

});
jnthnjns
  • 8,962
  • 4
  • 42
  • 65
0

You should probably just use a div or button type elements,not 'a' tag. change a tag to div or something ,it will work

<div ng-click="douserdetail(userdetail)" class="user-link">{{x.First_Name}}{{x.Last_time}}</div>
Arun
  • 1,177
  • 9
  • 15
  • 3
    are you sure? I would be suprised if this works, even in the AngularJS official documentation it states that you can put an ng-click inside an a tag. – Daniele Sassoli Oct 01 '15 at 12:57
  • 3
    An empty href attribute, which he already has, should also work – aw04 Oct 01 '15 at 13:00
  • @PankajParkar we have to remove href="" in 'a' tag ,otherwise it will not take click ,am i right? – Arun Oct 01 '15 at 13:01
  • Could also just preventdefault, but still I'm not sure it should be necessary – aw04 Oct 01 '15 at 13:01
  • http://stackoverflow.com/questions/14939385/href-overrides-ng-click-in-angular-js – Arun Oct 01 '15 at 13:06