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