0

AngularJS에서 $filter은 사용자에게 표시되는 데이터를 형식화하는 방법을 제공합니다. 그러나 $interpolate을 사용하면 문자열을 실시간으로 업데이트 할 수 있습니다.

$interpolate$filter은 서로 관련이 있습니까? 이 두 개념은 어떻게 다른가요?

답변

1

$ interpolate()는 특수 필터로 생각할 수 있습니다.

Grass is green. 
Milk is white. 
The sky is blue. 

당신은 나중에 변수 집합을 렌더링 컴파일 된 템플릿으로 (STRING) 보간 $의 반환 값 생각할 수 있습니다 : 생산합니다

var interpolationFunction = $interpolate('{{thing}} is {{color}}.'); 

var grass = {thing: 'Grass', color: 'green'}; 
console.log(interpolationFunction(grass)); 

// Or just. 
console.log(interpolationFunction({thing: 'Milk', color: 'white'})); 
console.log(interpolationFunction({thing: 'The sky', color: 'blue'})); 

.

$ filter (NAME)은 이전에 이름이 NAME 인 필터로 등록 된 함수를 반환합니다. 예를 들어 "대문자"필터는 인수를 대문자로 변환하고 "숫자"필터는 숫자를 포맷하며 "날짜"필터는 Date 객체의 형식을 지정하며 인수로 임의의 작업을 수행하는 고유의 명명 된 필터를 정의 할 수 있습니다.

관련 문제