如何使用$编译?

how to use $compile?

我尝试从 angular 控制器注入模板 html。我搜索了如何使用 $compile。所以,我对此进行了编程,但它不起作用:

  CustomersCtrl.$inject = ['$scope', '$http', '$location', '$modal', '$templateCache', '$window', '$compile'];

function CustomersCtrl($scope, $http, $location, $modal, $window, $compile) {

    var htmlContent = $('#pagination');
    htmlContent.load('Partials/Customers/pagination.html');
    $compile(htmlContent.contents())($scope);}

错误是:

类型错误:$compile 不是函数

欢迎大家的帮助。

初学者 DOM 代码不属于控制器。

接下来,当 angular 已经提供了多种方法来加载此内容时,使用 jQuery 加载此内容毫无意义。

一种简单的方法是使用 ng-include

<div id="pagination" ng-include src="'Partials/Customers/pagination.html'">

使用这样的指令意味着您不需要自己编译,它会自动为您完成。

我将 ID 留在了 angular 视图中,但很少需要 ID。

我强烈建议您在学习如何使用 angular 时删除所有对 jQuery 的使用。参见:"Thinking in AngularJS" if I have a jQuery background?