1

I have some troubles to get my directive to load in my ionic.js web app using angular. I can pass the variable {{someTitle}} from the controller to the template, however the directive does not get loaded, i.e. <div class="blaha" ng-transclude>abc123</div> does not get passed to the template... Am I missing something fatal below:

Ionic template:

<ion-view title="Roll the Dice">
  <ion-content has-tabs="true">
      <div my-dice>{{someTitle}}</div>

      <div class="card">
          <div class="item item-text-wrap">
              {{someTitle}}
          </div>
      </div>


      <button class="button button-dark button-full button-positive">
          Full Width Block Button
      </button>

  </ion-content>
</ion-view>

Controller code:

'use strict';
angular.module('TrueDice.controllers', [])


// A simple controller that fetches a list of data from a service
.controller('HistoryIndexCtrl', function($scope, TrueRandomService) {

        if($scope.rands="undefined"){
            $scope.rands = [];
        }
        TrueRandomService.getRand(1).success(function(data){
            $scope.rands.unshift(data);
            console.log(data);
        });
})
.controller('HistoryDetailCtrl', function($scope, $stateParams, TrueRandomService) {
  //currently empty

}).controller('RollViewCtrl', function($scope){
    $scope.someTitle="BLA";

}).directive('my-dice', ['$rootScope', function($rootScope) {
        return {
            restrict: 'E',
            template: '<div class="blaha" ng-transclude>abc123</div>',
            replace: true,
            transclude: true,
            scope: {},
            controller: function($scope, $element) {
               //currently empty
            }
        }
    }]);

NotWorking

1 Answer 1

6

Remove - from directive name:

directive('myDice', ['$rootScope', function($rootScope) {

and according to restrict: 'E', you should place element in html:

<my-dice>{{someTitle}}</my-dice>

example

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.