简体   繁体   中英

anchor tag with twitter bootstrap not working for ng-click

I have created a Fiddle for my scenario after trying this . Somehow the contractNum is not populating here but in my project it's populating.I have searched a lot and implemented all solutions what I got but can't make the anchor-link workable so that it can call a method in controller with a parameter.
If no parameter is passed in ng-click with anchor then it works fine but something is bugging it with parameter is passed. Please help me to resolve it.

View:

 <div ng-app="home" >

<div ng-controller="homeCtrl" ng-repeat="item in items">
                        Contract number<a href="" ng-click="getAssetDetail(item.jumboId)">  {{item.contractNum}} </a> <br />                 

</div>
<div>

and Controller:

angular.module('home', []).controller('homeCtrl', ['$scope', function ($scope, $http, $filter) {

 var items=[{contractNum:"123", serialNum:"ABC1" },
         {contractNum:"121", serialNum:"ABC2" },
         {contractNum:"124", serialNum:"ABC3" },
         {contractNum:"125", serialNum:"ABC4" } 
        ];


 $scope.getAssetDetail = function (jumboId) {

        alert('you got'+jumboId);

    };
 }]);

First off your items need to be a property on the $scope, not just a local var.

Secondly, there is no property called jumboId on your items, so that is why you get undefined.

Maybe you are trying to get the serialNum in your alert? If so take a look at this.

Fix your items:

$scope.items=[{contractNum:"123", serialNum:"ABC1" },
             {contractNum:"121", serialNum:"ABC2" },
             {contractNum:"124", serialNum:"ABC3" },
             {contractNum:"125", serialNum:"ABC4" } 
            ];

and fix your html:

Contract number<a href="" ng-click="getAssetDetail(item.serialNum)">  {{item.contractNum}} </a>

http://jsfiddle.net/gLrz0u4k/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM