I am new to MEAN. I am trying to write a program which list existing products and create new products.
first, I use a "NEW" link-button and I want it to show a form in the page that I am already at, when that button is clicked BUT when I click on that button it goes to a new page and does not show that form.
ProductController:
exports.create = function(req, res) {
var product = new ProductModel(req.body);
product.save(function() {
res.json(product);
});
};
exports.list = function(req, res) {
ProductModel.find(function(products) {
res.json(products);
});
};
ProductRoute:
module.exports = function(app) {
app.route('/products')
.get(products.list)
.post(products.create);
app.route('/')
.get(products.list)
.post(products.create);};
Angular ProductRoute:
angular.module('productsmodule').config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/', {
templateUrl: 'product/views/list-poducts.view.html'
}).
when('/products',{
templateUrl: 'products/views/list-poducts.view.html'
}).
when('/products/create',{
templateUrl: 'products/views/create_products.view.html'
}); }]);
service
angular.module('productsmodule').factory('ProductsService',['$resource', function($resource) { return $resource('/products/:productId', {
productId: '@_id'} });}]);
AngularController
angular.module('productsmodule').controller('ProductsController', ['$scope', '$location','ProductsService', function($scope, $location, ProductsService){
$scope.name2 = 'Initial Value List';
$scope.name3 = 'Initial Value Create';
$scope.create = function (){
var product = new Products({
name: this.name,
category: this.category,
price: this.price
});
product.$save(function(response){
$location.path('products/'+response._id);
});
};
$scope.find = function(){
$scope.products = ProductsService.query();
};![enter image description here][1]}]);
there might be a lot of silly mistakes but I do not have any access to any other source, So I really appreciate any help!
Cheers!