Javascript 从NodeJS到AngularJS获取一个对象
我在后端有一个对象。这就是我将这些对象发送到html的方式Javascript 从NodeJS到AngularJS获取一个对象,javascript,angularjs,Javascript,Angularjs,我在后端有一个对象。这就是我将这些对象发送到html的方式 res.render('product', {title:title, allCategories : allCategories, product : product[0]}) 我需要将产品对象发送给angularJs,以便我可以使用它进行一些操作。产品有多种颜色。我需要使用angularjs在下拉菜单中列出它们 <div id='image' ng-controller="productColor">
res.render('product', {title:title, allCategories : allCategories, product : product[0]})
我需要将产品对象发送给angularJs,以便我可以使用它进行一些操作。产品有多种颜色。我需要使用angularjs在下拉菜单中列出它们
<div id='image' ng-controller="productColor">
<select>
<option value="color" ng-repeat="color in colors">{{color}}</option>
</select>
</div>
我编的网址。但当我转到那个url时,第一部分就开始了
谢谢
-编辑:response.product返回未定义的在角度代码中,您正在创建一个数组,该数组的第一个索引处有一个数组:
$scope.colors = [
response.product.colors
]
把那一点改成
$scope.colors = response.product.colors;
它应该对你有用:
app.controller('productColor',['$scope','$http',函数($scope,$http){
var url='1〕http://localhost:3000/mens/mens-服装/男装套装/25604524'
$http.get(url).then(函数(响应){
console.log(response.data)
console.log(response.product)
$scope.colors=response.product.colors;
});
}]);代码>
{{color}}
这里显然不起作用,因为URL不存在,而且应用程序
在代码段中未设置。没问题,我理解响应。产品返回未定义。您写道您创建了URL,因此当我转到该URL res.render('product')时,无论如何都不会有响应,{title:title,allCategories:allCategories,product:product[0]})零件工程:/
$scope.colors = response.product.colors;