相关疑难解决方法(0)

AngularJS指令元素方法绑定 - TypeError:不能使用'in'运算符来搜索1中的'functionName'

这是主模板的控制器:

app.controller('OverviewCtrl', ['$scope', '$location', '$routeParams', 'websiteService', 'helperService', function($scope, $location, $routeParams, websiteService, helperService) {
    ...     
    $scope.editWebsite = function(id) {
        $location.path('/websites/edit/' + id);
    };
}]);
Run Code Online (Sandbox Code Playgroud)

这是指令:

app.directive('wdaWebsitesOverview', function() {
    return {
        restrict: 'E',
        scope: {
            heading: '=',
            websites: '=',
            editWebsite: '&'
        },
        templateUrl: 'views/websites-overview.html'
    }
});
Run Code Online (Sandbox Code Playgroud)

这是指令在主模板中的应用方式:

<wda-websites-overview heading="'All websites'" websites="websites" edit-website="editWebsite(id)"></wda-websites-overview>
Run Code Online (Sandbox Code Playgroud)

这是从指令模板(website-overview.html)调用的方法:

<td data-ng-click="editWebsite(website.id)">EDIT</td>
Run Code Online (Sandbox Code Playgroud)

问题:单击EDIT时,控制台中会出现此错误:

TypeError:无法使用"in"运算符在1中搜索"editWebsite"

有谁知道这里发生了什么?

javascript angularjs angularjs-directive angularjs-scope

85
推荐指数
2
解决办法
3万
查看次数