나는 포럼 스레드 (주제) 목록을 가지고 있는데, 각 사용자가 마우스를 올리면 별도의 패널에 메타 데이터를 표시하여 스레드가 무엇인지 식별 할 수 있습니다. selected $ emit의 매개 변수로 $ index를 전달하려고 시도하고 있지만이 함수를 손상시키는 것으로 보입니다.
보기 : (문제가 발생하는 경우)이 포함 대화 목록
<header ng-include="includes.header.src"></header>
<div id="content-wrapper">
<div ng-include="includes.threadList.src" id="content-left"></div>
<div id="content-divider"></div>
<div ng-include="includes.threadDetails.src" id="content-right"></div>
</div>
:
<ul id="threadList">
<li ng-repeat="thread in threadList | filter:includes.header.searchQuery" ng-mouseover="$emit('updateThreadDetails', {{$index}})">
<a href="/#/threads" ng-click="">
{{thread.title}}, moused over {{count}} times. This is item {{$index}}
</a>
</li>
</ul>
threadDetails은 다음과 같습니다
<h3>{{includes.threadDetails.title}}</h3>
컨트롤러 :
function threadListCtrl($scope){
$scope.count = 0;
$scope.$on('updateThreadDetails', function(event,index) {
$scope.count++;
$scope.includes.threadDetails.title = index; //$scope.threadList[index].title;
});
$scope.threadList = [
{title: 'I like horse'},
{title: 'I like turtle'},
{title: 'I like actor'}
];
}
ng-mouseover="$emit('updateThreadDetails', 'myString')"
을 통한 스팅 전달은 예상대로 작동합니다 (includes.threadDetails.title
은 'myString'
이됩니다).
I like horse, moused over 26 times. This is item 0
I like turtle, moused over 26 times. This is item 1
I like actor, moused over 26 times. This is item 2
{{$ 지수}} 출력이 병이됩니다 전달됩니다
및 'moused over x times'
X에서 0은 항상하고 스레드 세부 사항은 변경되지 : 다음 대화 목록에서 건강한 샘플 텍스트입니다. 해결 방법으로 나는 사전 설정을 시도 {{$ 지수}} 그래서 난 그냥이 작동하지 않았지만 thusly 히 원시적를 통과했다 :
ng-mouseover="index = '{{$index}}'; $emit('updateThreadDetails', index)"
당신이 NG-마우스 오버'말을 의미합니까 = "인덱스 = $ 지수; $가 방출 ('updateThreadDetails', $ index) "'? {{}}에 대한 지시어이기 때문에 구분자는 필요하지 않습니다. –
나는 완벽하게 작동했다. –