Javascript 将数据传递到动态AngularJS控制器

Javascript 将数据传递到动态AngularJS控制器,javascript,angularjs,Javascript,Angularjs,假设我们有一个容器,在其中添加动态html(带有angular指令) document.getElementById(“divContent”).innerHTML='{{test}}'; 以下是某个虚拟控制器的代码: angular.module(“TestApp”,[]).controller(“TestCtrl”,函数($scope) { $scope.test=“a”; }); 要初始化Angular,我们将使用bootstrap: angular.bootstrap(docum

假设我们有一个容器,在其中添加动态html(带有
angular
指令)


document.getElementById(“divContent”).innerHTML='{{test}}';
以下是某个虚拟控制器的代码:

angular.module(“TestApp”,[]).controller(“TestCtrl”,函数($scope)
{
$scope.test=“a”;
});
要初始化
Angular
,我们将使用
bootstrap

angular.bootstrap(document.getElementById(“divTest”),[“TestApp”);
所以问题是如何通过
测试
参数,它显示的是
b
,而不是
a

以下是使用方法

$(“#divContent”).html(
$compile(
“{{test}}”
)(范围)
);
但上述方法不起作用,因为控制器可能不可用

做一些类似于:

并将$compile注入控制器

$("#divContent").html(
      $compile(
        "<div id='divTest'>{{test}}</div>"
      )(scope)
);