2
我正在使用Angular.js从我的API中获取单个记录。我将记录作为对象返回,我可以记录对象并查看它的属性,但我无法访问任何属性。我刚刚得到undefined
。无法访问我的Javascript对象的属性
var template = Template.get({id: id});
$scope.template = template;
...
console.log(template); // displays object
console.log(template.content); // undefined
UPDATE
var id = $routeParams.templateId;
var template = Template.get({id: id});
$scope.template = template;
/*** Template placeholders ***/
$scope.updatePlaceholders = function() {
var placeholders = [];
var content = template.content;
console.log(template); // dumps the object in the screenshot
console.log("content" in template); // displays false
// get placeholders that match patter
var match = content.match(/{([A-z0-9]+)}/gmi);
...
}
$scope.$on('$viewContentLoaded', function(){
$scope.updatePlaceholders();
});
什么'console.log(“模板中的内容”)显示? – MaxArt 2013-05-02 15:23:57
@MaxArt未定义。他在那里作为评论。 – Yatrix 2013-05-02 15:24:44
@Yatrix'“content”in template'和'template.content'是两个完全不同的东西 – Ian 2013-05-02 15:25:23