나는 간단한 문자열이있다.
scope.$eval(templateString);
내 다음 단계는 $compile
데이터에이고 범위와 연결 :
link
함수 내에서, 나는 다음과 같은 코드를 실시하고 있습니다. 나는
$eval
을 수행 할 때
그러나, 나는 오류가 발생합니다 :
Uncaught Error: Syntax Error: Token 'span' is an unexpected token at
column 2 of the expression [<span>This is a test</span>]
starting at [span>This is a Test</span>].
을하지만 here있는 문서를 보면, 나는 제대로 아직 문자열이 평가하지 않는 단계를 수행 한 것으로 보인다.
편집 : 나는 문서에서 다음 예제를 사용하고 있습니다 : 나는 어떤 표정을보고 이미 저와 템플릿이 필요하지 않기 때문에 그러나 $watch
를 사용하고 있지 않다
angular.module('compile', [], function($compileProvider) {
// configure new 'compile' directive by passing a directive
// factory function. The factory function injects the '$compile'
$compileProvider.directive('compile', function($compile) {
// directive factory creates a link function
return function(scope, element, attrs) {
scope.$watch(
function(scope) {
// watch the 'compile' expression for changes
return scope.$eval(attrs.compile);
},
function(value) {
// when the 'compile' expression changes
// assign it into the current DOM
element.html(value);
// compile the new DOM and link it to the current
// scope.
// NOTE: we only compile .childNodes so that
// we don't get into infinite loop compiling ourselves
$compile(element.contents())(scope);
}
);
};
})
});
(templateString) .
설명서에 '$ eval'은 어디에도 언급되어 있지 않습니다. 템플리트를 직접'$ compile '하고'element'를 생성하는 범위를 제공해야합니다.'attrs' 요소를 통해 문자열을 얻지 않는 한'$ eval'은 필요 없습니다. –
@musically_ut 내가 사용하고있는 예제를 나타 내기 위해 내 질문을 업데이트했습니다. 평가하지 않으면'span' 태그 안에있는 각 표현식이 먼저 평가되지 않고 그대로 표시됩니다. 컴파일하기 전에 각도 표현식 (있는 경우)을 평가하기를 원합니다. – callmekatootie