2017-10-24 3 views
0

Das Routing einer angularjs-Komponente mit Camelcase-Bindung funktioniert bei mir nicht, ich weiß nicht warum.AngularJs 1.6 ComponentBindings

Hier ist das Beispiel

Komponente

angular. 
    module('pdaFile'). 
    component('pdaFile', { 
    templateUrl: 'app/myComponent/myComponent.html', 
    bindings:{ 
     data:"<", 
     dataFileId:"@", 
     datafileid:"@", 
     id:"@" 
    }, 
    controller: ['NgTableParams','UserAuthService', 
     function pdaFileController(NgTableParams,UserAuthService) { 
     var self=this; 

... 

self.$onInit = function() { 
      console.log(self.dataFileId); // undefined 
      console.log(self.id); // OK 
      console.log(self.datafileid); //OK 

     }; 


appConfig.js 

.. 

// Router

angular. 
    module('app') 
     .config(['$locationProvider', '$routeProvider', 
     function config($locationProvider, $routeProvider) { 
    $locationProvider.hashPrefix('!'); 
    $routeProvider. 
when('/pda', { 
      template: '<pda-file id="pippo" datafileid="current" data-file-id="current"></pda-file>'}) 
    . 

..

ich nicht in der Lage bin, die Bindung param dataFileId in irgendeiner Weise zu füllen. Es ist immer undefiniert. Ich versuchte mit

<pda-file data-file-id="current"></pda-file>' 

<pda-file dataFileId="current"></pda-file>' 

und andere Möglichkeiten. Stattdessen funktionieren die non camelcase param datafileid und id einwandfrei.

Jemand kann mir sagen, warum?

+1

würde ich vorschlagen, nicht Worte wie 'data' oder' data' als Namen Attribute Präfixe – Ferie

+0

Sie haben Recht. Der Wechsel von dataFileId zu dtFileId funktioniert einwandfrei, mit dt-file-id als Attribut – Massimo

Antwort

0

Haben Sie es versucht?

data-file-id="current" 

Oder

file-id="current" 

Dann

bindings:{ 
    fileId:"@", 
} 
+0

Ja, ich habe es versucht. Es funktioniert mit FileId. Das Problem liegt in der Verwendung von "Daten" als Präfix, was zu nicht gutem Verhalten führt, wie Feries Vorschlag. Die Verwendung von dtFileId funktioniert auch und dt-file-id als Tag-Attribut – Massimo

+0

So behebt Ihr Problem? –

Verwandte Themen