0

Here is my html snippet :

<div ng-controller="ctrl">
<custom-tag
title = "name"
body = "content">
</custom-tag>
</div>

Here is controller and directive written:

var mod = angular.module("main_module",[]);

//Controller
mod.controller("ctrl",function($scope) {
  $scope.name="Page Title";
  $scope.content="sample_template.html";
  });

//Directive
mod.directive("customTag", function() {
  return {
    'restrict' : 'E',
    'scope' : {
      'title' : '=',
      'body : '='
      },
    'templateUrl' : 'directive_template.html'
    };
  });
<!-- directive_template.html -->

<div>
  <div>{{title}}</div>
  <div ng-include="'{{body}}'"></div>
</div>

The actual html rendered by directive is this :

<div>
  <div ng-binding></div>
  <!-- ngInclude: '{{body}}' -->
</div>

Clearly it is not getting the directive scope variables from attributes in <custom_tag>

Please tell me why it is happening and how I resolve this issue. Thanks

4
  • Your directive is named customDirective, but your html is <custom-tag>... how is any of this working at all? Commented Sep 8, 2016 at 18:20
  • Sorry I actually renamed everything here. And in actual one, I didn't do this mistake.There is something else. Directive template is loading, only scope variables are not loading. Commented Sep 8, 2016 at 18:27
  • Try using 'scope as' Syntax in the view. Commented Sep 8, 2016 at 18:34
  • How? I couldn't understand what you said Commented Sep 8, 2016 at 18:50

1 Answer 1

1

Check the console for errors extra quotes and {{}} braces were breaking things.

<div>
  <div>{{title}}</div>
  <div ng-include="body"></div>
</div>

http://plnkr.co/edit/G9JfIJGhSghUbgkKLXnV?p=preview

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.