我的HTML是如何将角色的参数传递给指令函数?
<ul id="suggestions" class="suggestions-list"><li
ng-repeat="suggestion in suggestions track by $index"
class="suggestion-item"
ng-click="toggleSkill(suggestion, 'here')"
ng-class="{active : selectedIndex === $index}"
><span class="small clr-secondary">{{suggestion}} - {{$index}}</span></li></ul>
而在该指令,我有:
link: function(scope, elem, attrs) {
scope.toggleSkill = function(item, index) {
debugger
SkillsService.searchResults = []
if (scope.selectedTags.indexOf(scope.suggestions[index]) === -1) {
scope.selectedTags.push(scope.suggestions[index])
scope.searchText = ""
出于某种原因,index
在功能就会出现,undefined
。为什么会这样?
真的很奇怪......建议是否正确传递?如果你在你的函数内部尝试'console.log(arguments);',你能在某处看到'here'参数吗? – quirimmo
'建议'正确通过 – Shamoon