Javascript 将代码从jquery移动到angularjs
我在jQuery中有以下代码块,我需要将其转换为angularjs JS代码Javascript 将代码从jquery移动到angularjs,javascript,jquery,angularjs,Javascript,Jquery,Angularjs,我在jQuery中有以下代码块,我需要将其转换为angularjs JS代码 command: [ { name: "Delete", text: "<span class='glyphicon glyphicon-trash' aria-hidden='true'></span>", click: function (e) { e.preventD
command: [
{
name: "Delete",
text: "<span class='glyphicon glyphicon-trash' aria-hidden='true'></span>",
click: function (e) {
e.preventDefault();
//add a click event listener on the delete button
var tr = $(e.target).closest("tr"); //get the row for deletion
var data = this.dataItem(tr); //get the row data so it can be referred later
wnd.content(confirmationWindowTemplate(data)); //send the row data object to the template and render it
wnd.open().center();
wnd.title("Delete Prospect");
$("#yesButton").click(function (e) {
alert("hi")
})
//$("#noButton").click(function (e) {
$scope.noButton = function() {
alert("hi!");
}
},
]
<div class="pull-right">
<button class="btn btn-blue" id="yesButton">Yes</button>
<button class="btn btn-default" ng-click="noButton()"> No</button>
</div>
命令:[
{
名称:“删除”,
正文:“,
点击:功能(e){
e、 预防默认值();
//在“删除”按钮上添加单击事件侦听器
var tr=$(e.target).closest(“tr”);//获取要删除的行
var data=this.dataItem(tr);//获取行数据,以便稍后引用
content(confirmationWindowTemplate(data));//将行数据对象发送到模板并呈现它
wnd.open().center();
wnd.所有权(“删除潜在客户”);
$(“#是按钮”)。单击(函数(e){
警报(“hi”)
})
//$(“#noButton”)。单击(函数(e){
$scope.noButton=函数(){
警惕(“嗨!”);
}
},
]
HTML代码
command: [
{
name: "Delete",
text: "<span class='glyphicon glyphicon-trash' aria-hidden='true'></span>",
click: function (e) {
e.preventDefault();
//add a click event listener on the delete button
var tr = $(e.target).closest("tr"); //get the row for deletion
var data = this.dataItem(tr); //get the row data so it can be referred later
wnd.content(confirmationWindowTemplate(data)); //send the row data object to the template and render it
wnd.open().center();
wnd.title("Delete Prospect");
$("#yesButton").click(function (e) {
alert("hi")
})
//$("#noButton").click(function (e) {
$scope.noButton = function() {
alert("hi!");
}
},
]
<div class="pull-right">
<button class="btn btn-blue" id="yesButton">Yes</button>
<button class="btn btn-default" ng-click="noButton()"> No</button>
</div>
对
不
我没有发布完整的代码,因为它太长了。我想把这个jquery代码转换成angularjs。正如你所看到的,我试图分别用jquery和angularjs调用Yes和No函数。当我单击Yes时,我看到一条警告消息“hi”,但当我单击No时,我没有收到警告消息
如果这个问题没有提供足够的细节,我很抱歉。我在过去的两天里一直在讨论这个问题。如果您的代码
$scope.noButton=function(){alert(“hi!”);}
是否放置?根据我的angularjs知识,您在HTML代码中需要控制器,然后您可以在该控制器中使用ng单击
设置按钮,这将最终在您的angular控制器文件代码中绑定函数
Ref-
这里是您的yes按钮代码
$(“#yesButton”)。单击(函数(e){alert(“hi”)}
正在使用jQuery,因此它可以正常工作检查noButton()是否在作用域中,它是否在控制器的作用域中。检查调试控制台窗口中的错误