1

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!

syymza
  • 679
  • 1
  • 8
  • 23
Saeed Baba
  • 188
  • 2
  • 14

1 Answers1

0

Are you using mean.io or mean.js?

If you are using mean.js you should create your modules via the CLI, like this

$ yo meanjs:crud-module <module-name>

You can find out more here: http://meanjs.org/generator.html#crud-module

If you are using mean.io you can use the CLI, as well, but I'm not very fluent with that. Documentation here: http://learn.mean.io/#mean-stack-cli-overview

Hope this can help a little!

LucaApo
  • 74
  • 1
  • 3
  • mean.js if anyone have any simple mean application which works I would appreciate if you share it with me here – Saeed Baba May 20 '15 at 21:28