I'm creating my first directive and I'm running into some strange behaviour. The console.log() in my link-function is called twice. I've googled for some solutions, but I don't see how I need to change my code to change the behaviour...
My index.html:
<html>
<head>
<title>GCSE Directive TEST</title>
</head>
<body ng-app="gcseTest">
<google-image-search query="Test query"></google-image-search>
<!-- Scripts -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js"></script>
<script src="gcse-directive.js"></script>
</body>
</html>
gcse-directive:
angular.module('gcseTest', [])
.directive('googleImageSearch', [ function(){
return {
scope: {
query: '@'
},
templateUrl: 'gcse-popup.html',
restrict: 'E',
replace: true,
link: function ($scope, $element, $attrs) {
$scope.search = function(){
console.log("Gebruik query in link-functie: " + $scope.query);
return "Gebruik query via popup: " + $scope.query;
}
}
};
}]);
gcse-popup.html:
<div>
<h1>Directive Test</h1>
{{search(query)}}
</div>
Can somebody explain what is going on here?