Goal: I need to execute a method in a directive template html , the method is a member of an object which is passed to directive scope.
I am trying to get "Hello, world!" output. Can some one help please.
html:
var myApp = angular.module('myApp',[]);
myApp.directive('passObject', function() {
return {
restrict: 'E',
scope: { obj: '=' },
template: '<div>Hello, {{obj.func1()}}!</div>'
};
});
myApp.controller('MyCtrl', function ($scope) {
$scope.obj = { func1: "$scope.function1.toString()" };
$scoe.function1 = function() {
return "world!";
};
});
<div ng-controller="MyCtrl">
<pass-object obj="obj"></pass-object>
</div>