Custom directive [Solved]


#1

Ok so I’m obvious missing something…

Have tried both and

but I dont see my directive?
It works when I run it in the browser using “ionic run”

Here it is:

    (function() {
    'use strict';

    angular
        .module('starter')
        .directive('nameList', nameList);

    function nameList() {
        var directive = {
            restrict: 'AEC',
            templateUrl: '/components/nameList/nameList.template.html',
            scope: {
            },
            link: linkFunc,
            controller: Controller,
            controllerAs: 'vm',
            bindToController: true
        };

        return directive;

        function linkFunc(scope, el, attr, ctrl) {

        }
    }

    Controller.$inject = ['Names'];

    function Controller(Names) {
        var vm = this;

        activate();

        function activate() {
          Names.getAllNames(function(allNames) {
            vm.names = allNames;
          });
        }
    }
})();

The template:

<div>
  <div class="list list-inset">
    <label class="item item-input">
      <i class="icon ion-search placeholder-icon"></i>
      <input ng-model="filters.searchText" placeholder="Search" type="text">
    </label>
  </div>

  <ion-list>
    <ion-item collection-repeat="name in vm.names | orderBy:'tilltalsnamn' | filter:{tilltalsnamn: filters.searchText, gender: filters.gender}">
      <div class="row">
        <div class="col">
          {{name.tilltalsnamn}}
        </div>
        <div class="col">
          <i class="ion-{{name.gender}}"></i>
        </div>
      </div>
    </ion-item>
  </ion-list>
</div>

#2

okay and where do you use your directive in the template?
Can not find any matches of name-list as a classname, attributename or tagname


#3

Found the problem :smile:
it was the first “/” in templateUrl :stuck_out_tongue:

in a directive when naming it “nameList” the html reference will be “name-list” :wink: