how can we use $compile outside a directive in Angularjs

前端 未结 5 1941
我在风中等你
我在风中等你 2020-12-03 07:31

I want to use $compile in a controller inside a function and not in a directive. is it possible? I am trying the below code.

$compile(\'
5条回答
  •  误落风尘
    2020-12-03 07:51

    I recompiled my html by the following way when I was needed to recompile my html to apply the changes on the page.

    It happens when I was trying to go to other link and back again to the page but for some reason the angular code was not compiling.

    So I fixed this by compiling the html part of the page again at a load event.

    function OnLoad() {
    angular.element("form:first").injector().invoke(['$compile', function ($compile) {
        var $scope = angular.element("form:first").scope();
        $compile("form:first")($scope);
    }]);
    }
    

    Below is the app declaration.

    and OnLoad() function is assigned in a html element's onload event on that page.

提交回复
热议问题