angularjs – 使用来自点击某个指令的警报
发布时间:2020-12-17 08:07:47 所属栏目:安全 来源:网络整理
导读:新到角度 想要将表达式写入ng-click。 例: x.directive('li',function(){ return { restrict: 'E',replace: true,template: 'games game ng-click="(alert({{ game }})" ng-repeat="game in games" {{ game.team1 }} {{game.bets }} game/br/games ' } });
新到角度
想要将表达式写入ng-click。 例: x.directive('li',function(){ return { restrict: 'E',replace: true,template: '<games> <game ng-click="(alert({{ game }})" ng-repeat="game in games"> {{ game.team1 }} {{game.bets }} <game></br></games> ' } }); 我想通过点击提醒游戏,但我收到这个错误: Error: [$parse:syntax] Syntax Error: Token 'game' is unexpected,expecting [:] at column 11 of the expression [(alert({{ game }})] starting at [game }})].
当您要求点击“警报”时,它会在$范围内查找该方法,而不在此处。
看到这个plunkr我在这个范围上使用了一个功能来在点击指令时调用警报。 在控制器中我们设置功能: $scope.test = function(text) { alert(text); } 或者你可以做:$ scope.alert = alert.bind(window);.如果你这样做,它将无法将上下文绑定到窗口。 在指令的ng点击中,我们称之为我们的功能: ng-click="test(game)" (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |