AngularJS: Custom Directives – Using Isolated Scope


How do you pass data to your directive?

So now we have covered the most basic part of custom directives, and now you should learn how to pass data to it.

You can simple access the current scope from a controller and get the data this way.


angular.module('app', [])
.controller('HelloWorldController', ['$scope',function($scope) {
    $scope.message = "This is a wonderful world we live in!"
.directive('helloWorld', function () {
    return {
        restrict: 'E',
        templateUrl: 'template.html'

Html Code:

    <body ng-controller="HelloWorldController">


Your message:

And then in your template you simply use the curly braces to display the message from the current scope. (more…)