如何使用angular.element在JavaScript中获取angular init函数

如何使用angular.element在JavaScript中获取angular init函数,javascript,angularjs,Javascript,Angularjs,我的控制器名称是ViewPostOnThreadCntrl,控制器div的id是ViewPostOnThreadCntr。在JavaScript中调用ng init函数时,会显示以下错误: 未捕获的TypeError:无法读取未定义的属性“GetPostReplyByThreadId” 视图代码 <section class="trdsec" ng-controller="ViewPostOnThreadCntrl" id="ViewPostOnThreadCntrl" ng-cloak&

我的控制器名称是
ViewPostOnThreadCntrl
,控制器div的id是
ViewPostOnThreadCntr
。在JavaScript中调用
ng init
函数时,会显示以下错误:

未捕获的TypeError:无法读取未定义的属性“GetPostReplyByThreadId”

视图代码

<section class="trdsec" ng-controller="ViewPostOnThreadCntrl" id="ViewPostOnThreadCntrl" ng-cloak>
  <div ng-init="GetPostReplyByThreadId()">
  </div>
</section>

在角度控制器中定义一个函数,如下所示

$scope.GetPostReplyByThreadId = function(){

// your logic here...

}

删除angular.element(…)代码行

当我使用“angular.element('#ViewPostOnThreadCntrl').scope().GetPostReplyByThreadId();”然后出现“Uncaught Error:[jqLite:nosel]”错误这是JavaScript吗?完整显示控制器代码。$scope.GetPostReplyByThreadId已在中定义。行angular.element('#ViewPostOnThreadCntrl').scope()处出错。GetPostReplyByThreadId();“未捕获错误:[jqLite:nosel]errors.angularjs.org/1.4.6/jqLite/nosel”;使用angular.element(document.getElementById('#ViewPostOnThreadCntrl'))时出错。scope().GetPostReplyByThreadId();然后出现以下错误“UncaughtTypeError:无法读取未定义的属性“GetPostReplyByThreadId”
success: function (result) {
            isSuccess = result;
            if (result > 0) {
                angular.element('#ViewPostOnThreadCntrl').scope().GetPostReplyByThreadId();
                $(e).closest("form").find("#PostText").val("");
                if (ID == 0) {
                    alert("Post Replied successfully.");
                }
                else {
                    alert("Replied successfully.");
                }
                $('html, body').animate({ scrollTop: $(ID > 0 ? "#div-" + ID + "" : ".footer").offset().top }, 2000);
                if (ID == 0)
                    $('#ShowDiv').css({ 'display': 'none' });
            }
            else {
                alert("Post Replied Unsuccessfully.");

            }

        },
        error: function (result) {
            alert("Post Replied Unsuccessfully.");
        }

    });
$scope.GetPostReplyByThreadId = function(){

// your logic here...

}