0

Why i defined 'sayHi' in the controller, and it does not display in the template?

js:

(function(){
var app = angular.module('myApp', []);

app.directive("directive1", function(){
    return {
        restrict : 'E',
        scope: {

        },
        link : function($scope){        

        },

        controller: ['$scope', function($scope){
          $scope.sayHi = 'hi';
          window.console.log($scope.sayHi);
        }]

    };  
});
})();

html:

<div style="border: 1px solid; padding: 10px; min-height: 100px;">
Directive1 :   
<directive1>
    {{sayHi}}
</directive1>
</div>

detail plnkr

1
  • That controller is related to your first directive and not second Commented Jan 20, 2016 at 7:37

1 Answer 1

2

Your directive doesn't have any template. You need to add

template: '{{ sayHi }}',

To your directive definition. The content inside the <directive1></directive> does not constitute the template of the directive.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.