我是 AngularJs 的新手,ng-click 没有按预期工作。我在互联网上搜索,按照教程进行操作,(这是有效的)-但这不起作用!!!
我的代码:
<div class="row" ng:repeat="follower in myform.all_followers | partition:2">
<ons-col class="views-row" size="50" ng-repeat="data in follower" >
<img ng-src="http://dealsscanner.com/obaidtnc/plugmug/uploads/{{data.token}}/thumbnail/{{data.Path}}" alt="{{data.fname}}" ng-click="showDetail2(data.token)"/>
<h3 class="title" ng-click="showDetail2('ss')">{{data.fname}}</h3>
</ons-col>
</div>
这是我的 Controller
//Follows Controller
app.controller('FollowsController', function($scope, $http) {
var ukey = window.localStorage.ukey;
$scope.myform ={};
$scope.myform.reports ="";
$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";
var dataObject = "usertoken="+ukey;
var responsePromise = $http.post(server_url+"follows/", dataObject,{});
responsePromise.success(function(dataFromServer, status, headers, config) {
$scope.myform.all_followers = dataFromServer;
console.log(dataFromServer);
//alert(dataFromServer);
$scope.showDetail = function(index) {
profileusertoken = index;
$scope.ons.navigator.pushPage('profile.html');
}
function showDetail2(index) {
alert("here");
}
$scope.showDetail2 = showDetail2;
});
});
showDetail 和 showDetail2 都不工作 请帮忙 谢谢
最佳答案
只需将函数引用添加到 Controller 中的 $scope 即可:
例如,如果您希望函数 MyFunction 在 ng-click 中工作,只需添加到 Controller :
app.controller("MyController", ["$scope", function($scope) {
$scope.MyFunction = MyFunction;
}]);
关于javascript - Angular : ng-click not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25422584/