"bound m" 显示在 angular ng-repeat
"bound m" show in angular ng-repeat
我使用 restangular
连接到 REST API。我用这段代码定义了一个 ProductService.js
:
'use strict';
angular.module('app').service('ProductService', function($rootScope, Restangular) {
// Build collection /product URL
var _productService = Restangular.all('product');
this.list = function() {
// GET /api/product
return _productService.getList();
}
this.create = function(product) {
// POST /api/product/:id
_productService.post(product).then(function() {
$rootScope.$broadcast('product.create');
});
}
});
我在 ProductController.js
中使用此服务:
"use strict";
app.controller('ProductController',function($scope,$http,Restangular,ProductService){
// get products
$scope.products = ProductService.list();
// create product
$scope.create = function(product) {
ProductService.create(product);
};
// Event Listeners
$scope.$on('product.create', function(product) {
$scope.products = ProductService.list();
console.log('product create');
});
});
页面加载时一切正常,之后创建产品时显示此页面:
我解决了问题并将 $object
添加到 ProductService.js
中的列表函数:
this.list = function() {
// GET /api/product
return _productService.getList().$object;
}
我使用 restangular
连接到 REST API。我用这段代码定义了一个 ProductService.js
:
'use strict';
angular.module('app').service('ProductService', function($rootScope, Restangular) {
// Build collection /product URL
var _productService = Restangular.all('product');
this.list = function() {
// GET /api/product
return _productService.getList();
}
this.create = function(product) {
// POST /api/product/:id
_productService.post(product).then(function() {
$rootScope.$broadcast('product.create');
});
}
});
我在 ProductController.js
中使用此服务:
"use strict";
app.controller('ProductController',function($scope,$http,Restangular,ProductService){
// get products
$scope.products = ProductService.list();
// create product
$scope.create = function(product) {
ProductService.create(product);
};
// Event Listeners
$scope.$on('product.create', function(product) {
$scope.products = ProductService.list();
console.log('product create');
});
});
页面加载时一切正常,之后创建产品时显示此页面:
我解决了问题并将 $object
添加到 ProductService.js
中的列表函数:
this.list = function() {
// GET /api/product
return _productService.getList().$object;
}