1
function myController($scope,helperService) 
    { 

    function getFormattedDT() { 
     var localDate = "2016-04-04 12:55:55"; 
     var inputDate = helperService.parsedDate(helperService.formatDate(localDate)); 
    } 
    getFormattedDT(); 
    } 

hatası alıyorum "TypeError: helperService.formatDate bir işlev değil". i myController işlev tutarsanızİç içe geçirilmiş bağımlılık yöntemlerini bir yönerge denetleyicisinden nasıl çağırabilirim?

(function (myApp) 
{ 
    myApp.service('helperService',['$http','$q','$sce','miscService', function($http,$q,$sce,'miscService') { 

    function formatDate(dateTime) { 
     return .... 
    } 

    function parsedDate(date) { 
     return .... 
    } 

}(angular.module('myApp') 

Ama, o zaman iyi çalışır. Açısal olarak enjekte edilen bağımlılıklarda yuva yöntemlerini nasıl ararım.

+0

'helperService' kodunu gönderin. – Daniel

+0

eğer parsedDate yöntemi mevcutsa, bir yazım hatası olmalı. Tüm kodunuzla bir plnkr oluşturabilir misiniz? –

+0

@HuguesStefanski Doğru hata mesajıyla güncelledim. – JsLearner

cevap

0

Sizin helperService üzerinde yöntemlerle, böyle bir şey ile bir nesne döndürmesi gerekir:

(function (myApp) 
    { 
    myApp.service('helperService' 
    ['$http','$q','$sce','miscService', 
     function($http,$q,$sce,'miscService') { 

     function formatDate(dateTime) { 
      return .... 
     } 

     function parsedDate(date) { 
      return .... 
     } 

     return{ 
      parsedDate: parsedDate, 
      formatDate: formatDate 
     } 

    }(angular.module('myApp') 

angularservice kaydı kullanılmak üzere bir nesneyi döndüren bir yöntem bekliyor.

İlgili konular