javascript - AngularJS Directive element method binding - TypeError: Cannot use 'in' operator to search for 'functionName' in 1 -
this controller of main template:
app.controller('overviewctrl', ['$scope', '$location', '$routeparams', 'websiteservice', 'helperservice', function($scope, $location, $routeparams, websiteservice, helperservice) { ... $scope.editwebsite = function(id) { $location.path('/websites/edit/' + id); }; }]); this directive:
app.directive('wdawebsitesoverview', function() { return { restrict: 'e', scope: { heading: '=', websites: '=', editwebsite: '&' }, templateurl: 'views/websites-overview.html' } }); this how directive applied in main template:
<wda-websites-overview heading="'all websites'" websites="websites" edit-website="editwebsite(id)"></wda-websites-overview> and method called directive template (website-overview.html):
<td data-ng-click="editwebsite(website.id)">edit</td> question: when edit clicked, error appears in console:
typeerror: cannot use 'in' operator search 'editwebsite' in 1
does know goes on here?
since defined expression binding (&), need explicitely call json containing id if want bind in html edit-website="editwebsite(id)".
indeed, angular need understand id in html, , since not part of scope, need add called "locals" call doing:
data-ng-click="editwebsite({id: website.id})" or alternative:
data-ng-click="onclick(website.id)" with controller/link code:
$scope.onclick = function(id) { // ad "id" locals of "editwebsite" $scope.editwebsite({id: id}); } this documented here, example involving "close({message: 'closing now'})"
Comments
Post a Comment