2016-06-08 2 views
0

페이지의 첫 번째 h1 뒤에 html을 추가하려고합니다. angular.element는 h1 요소를 반환하지만 텍스트 "hello!"를 추가하지 않습니다. h1 요소 뒤에. 전체 JQuery 사용을 피하십시오. 아이디어가있는 사람은 누구입니까?AngularJS에서 jqLite를 사용하여 텍스트 추가

app.controller('Test', ['$scope', function ($scope) { 
    var h1 = angular.element(document).find("h1").length > 0 ? angular.element(document).find("h1")[0] : null 

    if (h1 != null) { 
     angular.element(h1).after(function() { 
      return "hello!" 
     }) 
    } 
}]); 

답변

1

after에 함수를 전달하지 말고 원하는 텍스트를 매개 변수로 포함하기 만하면됩니다.

if (h1 != null) { 
     angular.element(h1).after('Hello') 
}