2014-08-31 2 views
1

메시지를 인쇄하는 요소가 있습니다. 해당 메시지에는 동적 값이 들어 있습니다. 그렇다면 태그 내부에서 메시지가 평가되기 전에 메시지 내용을 어떻게 평가할 수 있습니까?다른 표현식에서 angularjs 표현식을 계산하는 방법

$scope.name = 'John' $scope.message = 'Hello {{name}}'

<li>{{message}}<li>

답변

3

당신은 그 표현을 평가하기 위해 $interpolate 서비스를 사용할 수 있습니다.

.controller('DemoController', function($scope, $interpolate) { 
    $scope.name = 'John'; 
    $scope.message = $interpolate('Hello {{name}}')($scope); 
}); 
1

ryeballar는 권리입니다. 또는 다음과 같이 할 수 있습니다.

$scope.name = 'John' 
$scope.message = 'Hello'+ $scope.name; 

<li>{{message}}<li> 
관련 문제