javascript - Angularjs service typerror undefined is not a function -


i have service in coffeescript so:

app.service 'calculateservice', ->   @calculate = (student) ->     if student.type == 'maturestudent'       student.age + 10     else       student.age + 5 

js version

app.service('calculateservice', function() {   return this.calculate = function(student) {     if (student.type === 'maturestudent') {       return student.age + 10;     } else {       return student.age + 5;     }   }; }); 

and controller so:

app.controller 'marksctrl', ($scope, $filter, calculateservice, lecture) ->  **create array** $scope.students = [] angular.foreach $scope.lecture.students, (student) ->     ......   $scope.students.push(student)  **save array** $scope.savestudents = ->     angular.foreach $scope.students, (student) ->         student.points = calculateservice.calculate(student) 

js version

app.controller('marksctrl', function($scope, $filter, calculateservice, lecture) {   $scope.students = [];   angular.foreach($scope.lecture.students, function(student) {     return $scope.students.push(student);   });   return $scope.savestudents = function() {     return angular.foreach($scope.students, function(student) {       return student.points = calculateservice.calculate(student);     });   }; }); 

i keep getting "typeerror undefined not function" @ when call calculateservice.calculate , have no idea why.

i've tried , works:

$scope.savestudents = ->   angular.foreach $scope.students, (student) ->     student.points = 2 

so problem arises when call service. idea how can make work?

it looks returning function service. instead not return function, service gets newed injector attach method instance , return nothing. in original case have invoke calculateservice(student)

try:

app.service 'calculateservice', ->    @calculate = (student) ->     if student.type == 'maturestudent'       student.age + 10     else       student.age + 5    return 

i have not used coffeescript, used transpiler figure out service definition is. in times of doubts these console logging of service see outputs (in case should see function itself).


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -