Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/446.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Angular js:一切正常,但在编译中用html创建的按钮不起作用_Javascript_Jquery_Angularjs - Fatal编程技术网

Javascript Angular js:一切正常,但在编译中用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>');

在我的代码中,除了下面的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>');
        $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);