我已从JSON文件中获取项目并将其发送到我的$scope
//JS controller
.controller('MyController', function($scope, $log) {
$http.get('JSON_FILE_URL').success(function(response){
$scope.responseData = response;
$scope.items = rundom(response);
});
$scope.refresh = function(data) {
$log.log('refresh data :'+data);
$scope.items = rundom(data);
};
}
// view.html
<ion-view view-title="myTitle" ng-controller="MyController">
<button ng-click="refresh({{responseData}})">refresh</button>
<ion-content overflow-scroll="true" padding="true" ng-cloak class="fullPage">
<div class="item item-text-wrap" ng-repeat="item in items">
<h1>{{ item['title'] }}</h1>
</div>
//some code here
</ion-content>
</ion-view>我在html上有检查元素,这些项目在我的函数里面。
<button ng-click="refresh({"id": 0, "title": "title 0"},{"id": 1, "title": "title 1"})">refresh</button>当我单击按钮进行刷新时,没有发生任何事情,但是我在日志上没有定义:refresh data :undefined
这是一个我没有考虑到的类型问题吗?
发布于 2016-02-05 02:59:06
您不需要在ng-click中使用尖括号。
ng-click="refresh()"它可以在函数内部访问$scope,所以不需要传递它
发布于 2016-02-05 17:43:10
奥利维尔的答案是正确的:ng-click="refresh(responseData)"
https://stackoverflow.com/questions/35209236
复制相似问题