2017-01-20 4 views
1
내가 사용 지침을

`에 함수가 아닙니다 mathjaxBind되지만, 아래와 같이 문제 : em.contents가 mathjaxBind` 지시어

enter image description here

어떻게 이러한 오류를 방지하려면? mathjaxBind 지침에

코드는 : $scope.$watch

.directive("mathjaxBind", function($compile) { 
     return { 
      restrict: "A", 
      controller: ["$scope", "$element", "$attrs", 
       function($scope, $element, $attrs) { 
        $scope.$watch($attrs.mathjaxBind, function(texExpression) { 
         var em = $element.html(texExpression); 
         $compile(em.contents())($scope); 
         MathJax.Hub.Queue(["Typeset", MathJax.Hub, $element[0]]); 
        }); 
       }] 
     }; 
    }) 

답변

0

첫 번째 매개 변수는 string 또는 function 중 하나이어야한다. string 인 경우 expression이어야합니다.

$attrs.mathjaxBind (string)을 전달하므로 undefined을 청취자 매개 변수 texExpression에 전달합니다. 메서드 html()$element 인 경우 undefined을 전달하면이 인스턴스가 반환되지 않습니다 (빈 문자열을 반환 함). 따라서 오류가 발생했습니다.

plunker example과 같은 값을 반환하는 함수로 감시자를 설정할 수 있습니다.