這是從MLAB定義我的產品文檔的摘錄:控制器無法識別對象的屬性
{
"_id": {
"$oid": "596161e1734d1d25634366ce"
},
"images": {
"regular": [
"Amana Electric Range in Stainless Steel-1.jpg",
"Amana Electric Range in Stainless Steel-2.jpg",
"Amana Electric Range in Stainless Steel-3.jpg",
"Amana Electric Range in Stainless Steel-4.jpg",
"Amana Electric Range in Stainless Steel-5.jpg"
]
}
}
這是對應型號的貓鼬的摘錄:
const ProductSchema = new Schema({
images:{}
});
var Product = mongoose.model('Product', ProductSchema, 'product');
module.exports=Product;
我想訪問在我的控制器中的圖像對象,如:
init = function() {
$scope.product = DataService.getProduct();
console.log('productController.product = ', $scope.product)
$mainImage = $scope.product.images.regular[0];
$productImages = $scope.product.images.regular;
};
但我得到以下錯誤:
angular.js:14700 TypeError: Cannot read property 'regular' of undefined
at init (productController.js:8)
at new <anonymous> (
我在角2類似的問題,並能夠通過定義我的圖片與任何類型的對象在我的模型來解決這個問題:
images: any;
如何解決這Angularjs?
產生額外的信息:按getProduct(生產
getProduct() {
return $filter('filter')(products, {'_id': productId});
}
產品):
[
{
"_id": "596161e1734d1d25634366ce",
"producttype": "stove",
"name": "30 in. 4.8 cu. ft. Electric Range in Stainless Steel",
"brand": "Amana",
"model": "AER6303MFS",
"price": 199.9,
"list_price": "301.00",
"description": "This 30 in. Amana Electric Range comes with Bake Assist Temps to help you get dinner going. Simply choose a preset temperature setting to get started. Or, set your bake or broil temperatures with Easy Touch Electronic Controls Plus, which are extra-large and easy-to-read. And when you need to know how your dinner is doing without opening the oven door, the Extra-Large Oven Window lets you see and savor.",
"rating": 5,
"sku": "1002064151",
"warranty": "ANSI Certified,CSA Certified",
"images": {
"stainless": [
"Amana Electric Range in Stainless Steel-1.jpg",
"Amana Electric Range in Stainless Steel-2.jpg",
"Amana Electric Range in Stainless Steel-3.jpg",
"Amana Electric Range in Stainless Steel-4.jpg",
"Amana Electric Range in Stainless Steel-5.jpg"
],
"white": [
"Amana Electric Range in White-1.jpg",
"Amana Electric Range in White-2.jpg",
"Amana Electric Range in White-3.jpg",
"Amana Electric Range in White-4.jpg"
],
"black": [
"Amana-black-1.jpg",
"Amana-black-2.jpg",
"Amana-black-3.jpg",
"Amana-black-4.jpg",
"Amana-black-5.jpg"
],
"regular": [
"Amana Electric Range in Stainless Steel-1.jpg",
"Amana Electric Range in Stainless Steel-2.jpg",
"Amana Electric Range in Stainless Steel-3.jpg",
"Amana Electric Range in Stainless Steel-4.jpg",
"Amana Electric Range in Stainless Steel-5.jpg"
]
},
"specifications": {
"dimensions": [
{
"value": "45.25",
"title": "Depth With Door(s) Open 90 Degrees (In.)"
},
{
"value": "25",
"title": "Oven Interior Depth (in)"
},
{
"value": "18.38",
"title": "Oven Interior Height (in)"
},
{
"value": "19",
"title": "Oven Interior Width (in)"
},
{
"value": "27.2",
"title": "Product Depth (in.)"
},
{
"value": "46.25",
"title": "Product Height (in.)"
},
{
"value": "29.88",
"title": "Product Width (in.)"
},
{
"value": "30 in.",
"title": "Range Size"
}
],
"details": [
{
"value": "Gas Range",
"title": "Appliance Type"
},
{
"value": "Cast Iron",
"title": "Burner Grate Material"
},
{
"value": "9500",
"title": "Burner No.1 BTU"
},
{
"value": "15000",
"title": "Burner No.2 BTU"
},
{
"value": "5000",
"title": "Burner No.3 BTU"
},
{
"value": "15000",
"title": "Burner No.4 BTU"
},
{
"value": "5.1",
"title": "Capacity of Oven (cu. ft.)"
},
{
"value": "Manual Clean",
"title": "Cleaning Type"
}
]
},
"feature": [
"Large 4.8 cu. ft. oven capacity with space for dinner and dessert",
"Versatile cooktop with multiple element options up to 1,800 watts",
"Bake Assist Temp presets make cooking even more convenient"
],
"$$hashKey": "object:181"
} ]
什麼是$ scope.product記錄? –
它正在記錄目標產品。 – koque
我明白,但請告訴我們記錄結果,以便我們可以告訴你你在訪問屬性時犯的錯誤。 –