简体   繁体   English

带有twitter bootstrap的锚标记不适用于ng-click

[英]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. 不知何故, contractNum不在这里填充,但是在我的项目中正在填充。我进行了很多搜索并实现了我所得到的所有解决方案,但无法使锚链接可用,因此它可以在带有参数的控制器中调用方法。
If no parameter is passed in ng-click with anchor then it works fine but something is bugging it with parameter is passed. 如果在ng-click中没有通过锚点传递任何参数,则它可以正常工作,但通过传递参数时会出现问题。 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) { 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. 首先,您的商品需要是$ scope上的属性,而不仅仅是本地var。

Secondly, there is no property called jumboId on your items, so that is why you get undefined. 其次,您的商品上没有名为jumboId的属性,因此这就是未定义的原因。

Maybe you are trying to get the serialNum in your alert? 也许您正试图在您的警报中获取serialNum? 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: 并修复您的html:

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

http://jsfiddle.net/gLrz0u4k/ http://jsfiddle.net/gLrz0u4k/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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