将 "factories" 重构为 $resource
refactoring "factories" into a $resource
您好,我已将 api 中用于编辑记录的先前功能转换为以下资源:
app.factory("Wine", function($resource){
return $resource("http://greatwines.8000.com/wines:id", {
//id as a variable
id: "@id"
},
{
update: {
method: "PUT"
}
});
});
我现在想通过触发一个带有 "wine" 记录的表单来使用它,以便在每种葡萄酒的 wine ng-repeat 中使用以下 CTA 进行编辑:
<a href="#/wines/{{wine.id}}" class="btn btn-default">Edit Wine</a>
在我的控制器中,我传递了 "Wine" 资源:
app.controller("editWineCtrl", function ($scope, $http, $routeParams, Wine, $location){
Wine.get({ id: $routeParams.id }, function(wine){
$scope.wine = wine;
});
...
然而,尽管形式 URL 返回 ID:
http://greatwines.8000.com/#/wines/1323
None 个字段,即:
div class="margin-top-20">
<input type="text" class="form-control" ng-model="wine.year" />
</div>
<div class="bold margin-top-20">
Grapes
</div>
<div class="margin-top-20">
<input type="text" class="form-control" ng-model="wine.grapes" />
</div>
正在填充。我使用资源的方式是否正确?
url 有错别字
wines:id
应该是
wines/:id
您好,我已将 api 中用于编辑记录的先前功能转换为以下资源:
app.factory("Wine", function($resource){
return $resource("http://greatwines.8000.com/wines:id", {
//id as a variable
id: "@id"
},
{
update: {
method: "PUT"
}
});
});
我现在想通过触发一个带有 "wine" 记录的表单来使用它,以便在每种葡萄酒的 wine ng-repeat 中使用以下 CTA 进行编辑:
<a href="#/wines/{{wine.id}}" class="btn btn-default">Edit Wine</a>
在我的控制器中,我传递了 "Wine" 资源:
app.controller("editWineCtrl", function ($scope, $http, $routeParams, Wine, $location){
Wine.get({ id: $routeParams.id }, function(wine){
$scope.wine = wine;
});
...
然而,尽管形式 URL 返回 ID:
http://greatwines.8000.com/#/wines/1323
None 个字段,即:
div class="margin-top-20">
<input type="text" class="form-control" ng-model="wine.year" />
</div>
<div class="bold margin-top-20">
Grapes
</div>
<div class="margin-top-20">
<input type="text" class="form-control" ng-model="wine.grapes" />
</div>
正在填充。我使用资源的方式是否正确?
url 有错别字
wines:id
应该是
wines/:id