SORU
22 Mart 2013, Cuma


Yönetmeliğe enjekte servisi

Aşağıda gibi yönetmeliğe uygun servisi enjekte etmeye çalışıyorum

 var app = angular.module('app',[]);
 app.factory('myData', function(){
     return {
        name : "myName"
     }
 });
 app.directive('changeIt',function($compile, myData){
    return {
            restrict: 'C',
            link: function (scope, element, attrs) {
                scope.name = myData.name;
            }
        }
 });

Ama bu Unknown provider: myDataProvider hata bana dönüyor. Birileri kodun içine bak ve eğer bir yerde hata yapıyorsam.. söyle bana, lütfen

CEVAP
22 Mart 2013, Cuma


Direktifin enjeksiyon yapabilirsin, başka yerde yok gibi görünüyor.

app.directive('changeIt', ['$compile', 'myData', function($compile, myData){
    return {
        restrict: 'C',
        link: function (scope, element, attrs) {
            scope.name = myData.name;
        }
    }
 }]);

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Matthew Smith

    Matthew Smit

    24 Mayıs 2010
  • paulandstorm

    paulandstorm

    4 EYLÜL 2006
  • Sergio Lafuente Rubio

    Sergio Lafue

    11 Aralık 2008