아래 코드에서 console.log($scope.gradeC.title);
은 올바른 출력을 보여줍니다. 다음 콘솔 라인은 예상 출력을 보여주지 않습니다. 나는이 행동을 이해하지 못한다. 모든 제안/포인터는 내가 이것을 이해하는 데 도움이 될 것입니다.객체 별 객체 배열의 각도 필터
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<script>
var myApp=angular.module("myApp", []);
myApp.controller('myCtrl', function($scope, $filter)
{
console.log("Inside controller");
$scope.results = {
year:2013,
subjects:[
{title:'English',grade:'A'},
{title:'Maths',grade:'A'},
{title:'Science',grade:'B'},
{title:'Geography',grade:'C'}
]
};
console.log($scope.results);
$scope.gradeC = $filter('filter')($scope.results.subjects, {grade: 'B'})[0];
console.log($scope.gradeC.title);
console.log(($scope.results.subjects|{grade: 'B'})[0].title);
});
</script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<h4>Printing div</h4>
</body>
</html>
유 주제 속성에 필터를 호출 하시겠습니까? –
"* 올바른 출력을 보여줍니다 *"- 어느 것입니까? – Rafalon
올바른 출력은 C 등급의 지리입니다. –