HTML中直接来自JSON的角度数据
Angular data from JSON directly in HTML
如果有直接控制器:
controller: function($scope, $http){
$http.get(templateSource+'/object.customer')
.then(function(result){
$scope = result.data;
});
}
我的object.customer文件看起来像:
[{"customer":{"name":"Bert","email":"bert@gmail.com"}}]
现在我想访问电子邮件,所以我做了(HTML)
{{customer.email}}
但这是不正确的,所以我的问题是,如何访问电子邮件?
更新
设置:
controller: function($scope, $http){
$http.get(templateSource+'/object.customer')
.then(function(result){
$scope.customer = {};
angular.extend($scope.customer,result.data[0]);
console.log($scope.customer.email);
});
}
在控制台.log unidentified
中给我。但是,如果我将其设置为console.log($scope.customer);
,我会得到:
Object 0:
Object customer:
Object email: "bert@gmail.com"
name: "Bert"
console.log(result.data)
是
[Object]
0: Object
customer: Object
email: "bert@gmail.com"
name: "Bert"
使用angular.extend
controller: function($scope, $http){
$http.get(templateSource+'/object.customer')
.then(function(result){
angular.extend($scope,result.data[0])
});
}
然后,您可以在控制器中使用$scope.customer.email.
,也可以在html中使用{{customer.email}}
。
相关文章:
- 无法使用变量访问数据 JSON
- 使用 ng-repeat解析不均匀数据/ json对象
- 在没有jsonp的情况下从另一个域获取数据(json格式)
- 如何获取带参数的数据json
- 如何在android中显示实时雅虎金融股票数据..json格式如下所示
- 使用 JavaScript 将数据 json 显示到网页中
- 高位图表来源于API数据(JSON)
- 使用动态数据json初始化同位素
- Django:将数据JSON从视图传递给javascript
- 存储配置数据 (json)
- 未捕获的SyntaxError:意外的标识符图像数据json
- 接收数据json/jquery
- Jquery数据表数据json
- 不能在cakephp中使用数组数据json
- 在不锁定浏览器的情况下,将大数据JSON从REST请求反序列化为对象
- 如何读取数据JSON格式数组的字符串数据
- 我有一个流星应用程序,需要从/public/_assets/results/mmresults读取数据.Json文件,在
- 数据json不显示在html
- 使用2个下拉列表创建2个并排的表行来比较数据- JSON
- 需要将复杂的json对象转换为合适的angularjs UI树数据json结构