나는이 일부 코드가 비슷한이 있다면, 어떻게 호출에 대해 갈 것이라고 getUserName()
내부 기능 ng-repeat
. 나는 더 일찍 그것을 시도했지만 작동했지만 더 이상 작동하지 않습니다.
var user_reviews = [{
user: {
name: "John Doe"
},
review: {
item: "Shure SE215"
}
}]
var app = angular.module("ExApp", []);
app.controller("TestController", function($scope) {
$scope.reviews = user_reviews;
$scope.getUserName = function() {
return $scope.user.name;
}
});
HTML
<div ng-controller="TestController">
<div ng-repeat="review in reviews">
<p>{{review.getUserName()}}</p>
</div>
</div>
scope.getUserName ()이 예제 에서처럼 사소하지 않다고 가정하면 대신 이것을 할 수 있습니다.
// Pass the `review` object as argument
$scope.getUserName = function(review){
return review.user.name; // get the user name from it
}
HTML, review
매개 변수로 전달
<div ng-controller="TestController">
<div ng-repeat="review in reviews">
<p>{{getUserName(review)}}</p>
</div>
</div>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다