2016-04-21 8 views
6

Mam router państwa jako takie:nie może wiązać się z kontrolera bez identyfikatora do dyrektywy + angularjs

$stateProvider 
    .state('home', { 
    url: '/', 
    templateUrl: 'spa/layouts/home.html', 
    controller: 'HomeController', 
    controllerAs: 'ctrl' 
    }); 

W moim home.html szablonie mam:

<div class="row main-body"> 
    <aside class="col-md-2 sidebarNav"> 
    <div>...</div> 
    </aside> 

    <section class="col-md-10 main-container"> 
    <div>..</div> 

    <my-list list-items={{ ctrl.listItems }}></my-list> 
    </section> 
</div> 

w dyrektywie moja-lista Mam następujące:

var templateUrl = 'spa/components/classList/classList.html'; 

angular 
    .module('directives') 
    .directive('myList', component); 

function component() { 
    return { 
    templateUrl: templateUrl, 
    controller: classListDir, 
    contollerAs: '$ctrl', 
    scope: { 
     listItems: '@' 
    }, 
    bindToController: true, 
    }; 
} 

classListDir.$inject = ['$scope']; 

function classListDir($scope) { 
    var $ctrl = this; 
    console.log($ctrl); 
} 

Przeczytałem i ponownie przeczytałem https://docs.angularjs.org/error/$compile/noident?p0=myList. myślę moje oferty walizce z drugim

// porządku, gdyż dyrektywa wykorzystuje właściwość controllerAs do ręcznym

// identyfikator kontrolera.

Nadal dostaję komunikat o błędzie. Nie rozumiem powiązania z błędem identyfikatora. Czy ktoś może to wyjaśnić.

Odpowiedz

14

Znaleziony problem:

contollerAs: '$ ctrl'

literówkę.

+2

Dla mnie było to, że brakowało mi razem własności 'controllerAs'. –

Powiązane problemy