角度事件绑定问题 [英] Angular event binding issue

查看:69
本文介绍了角度事件绑定问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计我有角度 ng-Click 的问题。



我的控制器:



  var  ParentController = function(){

this .MyEvent = function(){
alert(' foo-bar );
};

this .AddHTML = function(){
$( #ButtonSec)。html(' < input type ='按钮' ng-click =' Parent.MyEvent()' value ='内部按钮' />');
};

};

angular.module(' myApp',[])。controller( ' ParentController',ParentController);





HTML - 1(按预期工作按钮ng-click按预期绑定到'内部按钮'):



 <   div     ng-app   ='  testComponent'  >  
< div id = content ng-controller = ParentController as Parent >
< div id = ButtonSec >
< 输入 type =' 按钮' ng-click =' Parent.MyEvent()' value =' 内部按钮'
/ >
< / div >
< ; / div >
< / div >







HTML-2(不工作):使用添加HTML 按钮渲染html时。事件没有绑定到内部按钮应该(重要的是我不能根据客户要求使用$ scope)

 <   div     ng-app   ='  testComponent' >  
< div id = content ng-controller = ParentController as Parent >
< div id = ButtonSec >

< / div >
< < span class =code-leadattribute> / div >
< 输入 type =' button' ng-click =' Parent.AddHTML()' value =' 添加HTML / >
< / div >







伙计们请帮助.....

解决方案

#ButtonSec)。html(' < input type ='按钮' ng-click =' Parent.MyEvent()' value ='内部按钮' />');
};

};

angular.module(' myApp',[])。controller( ' ParentController',ParentController);





HTML - 1(按预期工作按钮ng-click按预期绑定到'内部按钮'):



 <   div     ng-app   ='  testComponent'  >  
< div id = content ng-controller = ParentController as Parent >
< div id = ButtonSec >
< 输入 type =' 按钮' ng-click =' Parent.MyEvent()' value =' 内部按钮'
/ >
< / div >
< ; / div >
< / div >







HTML-2(不工作):使用添加HTML 按钮渲染html时。事件没有绑定到内部按钮应该(重要的是我不能使用


范围根据客户要求)

< pre lang =xml> < div ng-app =' testComponent' >
< div id = content ng-controller = ParentController as Parent >
< div id = ButtonSec >

< / div >
< / div >
< 输入 类型 =' 按钮' ng-click =' Parent.AddHTML( )' value =' 添加HTML' / >
< / div >







伙计们请帮助.....

Guys I am having problem problem with angular ng-Click.

My Controller:

var ParentController = function ( ) {

    this.MyEvent = function () {
        alert('foo-bar');
    };

    this.AddHTML= function () {
       $("#ButtonSec").html('<input type='button' ng-click='Parent.MyEvent()'                value='inner button'/>');
    };

};

angular.module('myApp', []).controller('ParentController', ParentController);



HTML - 1 (Works as expected button ng-click binds to 'inner button' as expected):

<div ng-app='testComponent'>
     <div id="content" ng-controller="ParentController as Parent">
       <div id="ButtonSec">
            <input type='button' ng-click='Parent.MyEvent()' value='inner button'/>
       </div>
    </div>
</div>




HTML-2 (Not working):When rendering html using Add HTML button. Event not binding to inner button as it should (important thing I can't use $scope as per client requirement)

<div ng-app='testComponent'>
     <div id="content" ng-controller="ParentController as Parent">
       <div id="ButtonSec">

       </div>
    </div>
    <input type='button' ng-click='Parent.AddHTML()' value='Add HTML'/>
</div>




Guys please help .....

解决方案

("#ButtonSec").html('<input type='button' ng-click='Parent.MyEvent()' value='inner button'/>'); }; }; angular.module('myApp', []).controller('ParentController', ParentController);



HTML - 1 (Works as expected button ng-click binds to 'inner button' as expected):

<div ng-app='testComponent'>
     <div id="content" ng-controller="ParentController as Parent">
       <div id="ButtonSec">
            <input type='button' ng-click='Parent.MyEvent()' value='inner button'/>
       </div>
    </div>
</div>




HTML-2 (Not working):When rendering html using Add HTML button. Event not binding to inner button as it should (important thing I can't use


scope as per client requirement)

<div ng-app='testComponent'>
     <div id="content" ng-controller="ParentController as Parent">
       <div id="ButtonSec">

       </div>
    </div>
    <input type='button' ng-click='Parent.AddHTML()' value='Add HTML'/>
</div>




Guys please help .....


这篇关于角度事件绑定问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆