我的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