0

I´m using loopback with angular JS. I have a Person model on loopback and generated the lb-services.js to get acces to the Person model.

I added the lb-services to the module:

(function() {
  'use strict';

  angular
    .module('frontend', ['ngAnimate', 'ngCookies', 'ngTouch', 'ngSanitize', 'ngMessages', 'ngAria', 'ngResource', 'ngRoute', 'ui.bootstrap', 'toastr','lbServices']);

})();

However on my PersonsController when calling the createPerson() method I´m getting that Persons is undefined. I don´t understand why, since I have the dependecy on the controller.

This is my code:

angular.module('frontend').controller('PersonsController',['$scope','Person',function($scope){
  $scope.person = {name:'guest',last_name:"none",age:55};

  $scope.createPerson= function(){
    console.log("CREATING PERSON...");
    Person.create({name:$scope.person.name,last_name:$scope.person.last_name,age:$scope.person.age}).$promise
      .then(function(){
          console.log("Created person.")
      });

  };

}])

Can anyone help me out?

1
  • 1
    You are not including Person in your controller function ['$scope','Person',function($scope) Commented May 13, 2016 at 19:01

1 Answer 1

1
angular.module('frontend').controller('PersonsController',['$scope','Person',function($scope, Person){

just add Person as second parameter in function declaration and read the docs about DI in angular.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot for your help. That solved my problem :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.