0

I have the following directive:

.directive("feedList", function() {
            return {
                restrict: 'E',
                scope: {
                    feeds: '=feedData'
                },
                templateUrl: 'jstemplates/feed-list.html',


                link: function(scope) {

                    angular.forEach(scope.feeds, function(value, key) {
                        if(value.who.fullname == " "){
                            scope.feeds[key].fullname = "email";
                        }
                          console.log(value.who.fullname);
                    });

                }
        }
    })

Inside my template there is an event: ng-click="do()". How to handle this event in directive ot in parent controller?

1
  • You didn't define $scope.do() in your link function. What's the function supposed to do? Where is it defined? Commented Mar 8, 2017 at 14:45

1 Answer 1

2

As it's your isolated scope directive, so pass the callback function and then call that function directly from template or from controller or link function. Working fiddle

var app = angular.module('myApp', []);
app.controller('AppCtrl', function($scope){
		$scope.testFunction = function(){
  			alert("Called from isolated scope directive");
  	};
});

app.directive("isolatedScopeDirective", function(){
    return{
        scope:{
         go:"&"
        },
        template : `<button ng-click='go()'>Test Button</button>`
    };
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-controller="AppCtrl">
    <isolated-scope-directive go="testFunction()"></isolated-scope-directive>
</div>

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

2 Comments

Can you share example?
Sure. Just wait for some time.

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.