我需要动态地将一个按钮添加到我的html代码中。问题在于它内部有一个角度链接,一旦页面加载就无法工作。我一直在研究,它看起来像我需要使用$编译,以使其工作。
下面两个代码我想:
CODE 1
angular.injector(['ng']).invoke(['$compile', '$rootScope', function(compile, rootScope){
var scope = rootScope.$new();
var result = compile('<a ui-sref="app.form.matter({method:\'new\',id:\'\'})" type="button" class="btn dark_blue_bomhard m-b-5 nuevocliente" >New matter</a>')(scope);
scope.$digest();
$("div.toolbar").append(result);
}]);
此代码给了我没有错误,甚至把它必须是该按钮,但链接仍然这么想的作品。
CODE 2
angular.element("div.toolbar").append($compile('<a ui-sref="app.form.matter({method:\'new\',id:\'\'})" type="button" class="btn dark_blue_bomhard m-b-5 nuevocliente" >New matter</a>'))(scope);
此代码第二行给我一个错误:“的ReferenceError:$编译没有定义”
我有两个代码(不是在同一时间)在控制器中。
任何想法?
混淆自己打针改变字符串版本和功能参数的名称 – charlietfl
按钮不起作用,因为你不包括'在喷油器的UI,route'。 – georgeawg