Javascript Angular js:一切正常,但在编译中用html创建的按钮不起作用
在我的代码中,除了下面的HTML行之外,一切都很好Javascript Angular js:一切正常,但在编译中用html创建的按钮不起作用,javascript,jquery,angularjs,Javascript,Jquery,Angularjs,在我的代码中,除了下面的HTML行之外,一切都很好 > $compile('<button class="btn btn-link ng-scope" data-ng-click="Flow.GetFarePriceRule('+ start_point +','+ end_point +')">'+ $scope.fare_base_code_array[i-1].FareBasis["@attributes"].Code +'</button>');
> $compile('<button class="btn btn-link ng-scope" data-ng-click="Flow.GetFarePriceRule('+ start_point +','+ end_point +')">'+ $scope.fare_base_code_array[i-1].FareBasis["@attributes"].Code +'</button>');
$timeout(() => {
console.log($el.prop('outerHTML'))
});
请帮我摆脱困境outerHtml返回字符串,简单字符串。因此,您将放弃所有绑定。 这行不通:
var $el = $compile...
vat html = $el.prop('outerHTML')
someElement.html(html);
这将:
var $el = $compile...
someElement.append($el);
另外,我知道你是Jquery的粉丝,但最好不要在角度项目中使用它。我认为
数据属性不是问题所在。我在这里猜测的是,一旦您将函数分配给$scope
,您将调用Flow.GetFarePriceRule
,而不仅仅是GetFarePriceRule
。另外,你没有在$compile
上绑定$scope
。你好@LuizCarlos谢谢你的回复我现在就做了我编辑了代码你现在能给我建议吗?我忘了写$scope,我看到您在$compile
中添加了$scope
,但是您的数据ng click=“Flow.GetFarePriceRule(…
)仍然不正确。您应该将其重写为:数据ng click=“GetFarePriceRule
。
var $el = $compile...
vat html = $el.prop('outerHTML')
someElement.html(html);
var $el = $compile...
someElement.append($el);