我正在尝试解析json
文件,并希望在视图上显示。我能够在控制台上显示数据,但我无法在视图上显示。我正在使用ng-repeat。但是,它没有用。
另外,我尝试了 $ scope。$ apply ,但是它已经运行了错误和摘要周期,但数据没有显示,为什么?
以下是我的plunker链接:
http://plnkr.co/edit/uyyhxex5gubzTJSZipV0?p=preview
HelloWorldService.doWork().then(function(data){
console.log("data received to Ctrl");
$scope.data=data.employees;
$scope.hide();
// $scope.$apply();
})
答案 0 :(得分:1)
在服务中,您应该使用angular.fromJson(e.data)
将String转换为Json,它可以正常工作。参见工作示例
答案 1 :(得分:0)
$scope.data = JSON.parse(data).employees
答案 2 :(得分:0)
您的tableView
是一个字符串。您需要先使用heightForRowAtIndexPath
对其进行解析,然后才能使用它。
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
print("idx = \(indexPath.row)")
return super.tableView(tableView, heightForRowAtIndexPath: indexPath)
}