0

I am new to mean and and i am able to apply CRUD operations. Now I want to call more actions from Node JS controller from view that is Angular JS and I am refering this link https://github.com/jpotts18/mean-stack-relational for core model.

this is controller file design.js

exports.get_designs = function(req, res) {
    console.log('in design  node controllrrrrr get designs');
    db.designs.findAll({ where: {competition_id: req.params.competitionId} }).success(function(designs){
        return res.jsonp(designs);
    }).error(function(err){
        return res.render('error', {
            error: err,
            status: 500
        });
    });
};

In Angular controller

angular.module('mean.designs').controller('DesignsController', ['$scope', '$routeParams', '$location', 'Global', 'Designs',function($scope, $routeParams, $location, Global, Designs) {
    $scope.global = Global;

$scope.get_init_records = function() {
        console.log('in get init records comp id :  ' + JSON.stringify($routeParams.competitionId));
        Designs.query({
            competitionId: $routeParams.competitionId
        }, function(designs) {
            console.log(designs);
            $scope.designs = designs;

        });
};
}]);

and in services design.js

angular.module('mean.designs').factory("Designs", ['$resource', function($resource) {
    return $resource('designs/:designId', {
        designId: '@id'
    }, {
        update: {
            method: 'PUT'
        }
    });
}]);

In view

<section data-ng-controller="DesignsController" data-ng-init="get_init_records()" />

I can be able to call get_init_records this init method but later I dont know what is happening there ... and when I googled results like use $http but how to do this ? Thanks for help

Vishwanath
  • 6,284
  • 4
  • 38
  • 57
Gaurav Mamidwar
  • 338
  • 1
  • 12
  • I am not really sure what your question is, but I think it's worth mentioning that `$resource` returns a promise which means you have to use `then()`. Have a look at this question http://stackoverflow.com/questions/19490560/angularjs-resource-promise – Roco CTZ Jan 30 '15 at 08:31
  • Thanks. Actually I want to call nodejs method named as exports.get_designs from angular controller's $scope.get_init_records this method which I am not able to call . This is the question basically. – Gaurav Mamidwar Jan 30 '15 at 09:39
  • Problem reolved . I used service $http and now able to call nodejs method. Thanks – Gaurav Mamidwar Feb 02 '15 at 07:08

0 Answers0