草庐IT

event-binding

全部标签

javascript - AngularJS 指令 : template with scope value (ng-bind-html)

我有这样的指令:...template:function(element,attrs){varhtmlTemplate='\\';returnhtmlTemplate;},...(如你所见,我也在使用翻译插件)我有一个问题:在范围内这个值正在改变,但它在指令中没有改变(当我使用attrs-params时(当然,如果customDynamicText是静态字符串-一切正常)-但我有一个动态变量customDynamicText我如何在directivetemplate和ng-bind-html中使用这个动态变量。这可能吗? 最佳答案

javascript - 使用绑定(bind)将 Angular 组件编译为 HTML

我需要为我的map标记气球正文提供一个可靠的HTML字符串。我想让气球成为一个Angular组件,并使用绑定(bind)和内置指令(*ngFor、*ngIf等)。所以我正在寻找一种方法来评估组件模板中的所有绑定(bind)并将结果编译为字符串...如何实现这个或者如果这个方法是非Angular——推荐的模式是什么?//Componentimport{Component}from'@angular2/core';import{AnyThing}from'./somewhere/in/my/app/anything.model.ts';@Component({selector:'my-ba

javascript - 在 React Components 中绑定(bind)方法的首选方式

截至2017年11月,我知道了几种将方法绑定(bind)到React组件的方法,以便this关键字指向拥有该方法的React元素(例如,在事件处理程序中是必需的)1。在构造函数中绑定(bind)classAextendsReact.Component{constructor(props){super(props)this._eventHandler=this._eventHandler.bind(this)}_eventHandler(){//...}render(){return}}2。render()中的箭头函数classAextendsReact.Component{_event

javascript - 使用 vue-router 将查询绑定(bind)到 props

是否可以以声明方式将查询值绑定(bind)到props?我希望/my-foo?bar=my-bar传递Prop{foo:"my-foo",bar:"my-bar"}.我目前正在使用这样的东西:exportdefaultnewRouter({routes:[{path:"/:foo",name:"Foo",component:FooPage,props:route=>({foo:route.params.foo,bar:route.query.bar})}]});我正在寻找类似的东西:exportdefaultnewRouter({routes:[{path:"/:foo?bar=:ba

javascript - 如何使用 TypeScript Controller 和 Angular Js 绑定(bind)数据

我正在玩TypeScript。我已经将我的angularjsController转换为TypeScript但我在ng-repeater中遇到问题。(我在下面附上了我的Controller代码:-classCustomCtrl{publiccustomer;publicticket;publicservices;publiccust_File;publicticket_file;publicservice_file;static$inject=['$scope','$http','$templateCache'];constructor(private$http,private$temp

javascript - AngularJS:数组之间的数据绑定(bind)

给定一个数组sourceArray我想创建一个targetArray,它依赖于第一个数组的条目。这意味着创建的数组应包含每个源条目的条目,并在sourceArray更改时更新。但是,修改targetArray永远不会更新源。这Plunker只要sourceArray是静态的,就可以正常工作。一旦您开始修改源条目,它显然不会正确更新目标,因为我缺少适当的数据绑定(bind)机制。我是否需要通过观察sourceArray手动更新targetArray或者Angular是否实现了任何一种单向数据绑定(bind)机制,我可以使用它来保留两个数组同步? 最佳答案

javascript - 为什么在使用相同的 location.href(或空)推送时 window.onpopstate 上的 event.state 为空

在不更改URL的情况下推送到历史记录并设置数据时:window.history.pushState({stateName:"myStateName",randomData:window.Math.random()},"myStateName",location.href);....然后监听弹出事件并通过按下浏览器中的返回按钮触发它:window.onpopstate=function(event){console.log(event.state);//logsnull}大多数时候你会得到null作为状态值而不是:{stateName:"myStateName",randomData:0

javascript - 单元测试 : simulate the click event of child component in parent using enzyme

我有一个父组件和一个只是“标签”元素的子组件。当我点击子元素时,我需要调用父组件中的函数。我希望它被调用,但状态没有改变,当我看到覆盖文件时,函数没有被调用。**更新:**该代码适用于开发。只是单元测试失败了。这是我的父组件父类.jsexportdefaultclassParentextendsComponent{constructor(props){super(props)this.state={clickedChild:false}this.handleChildClick=this.handleChildClick.bind(this)}handleChildClick(inde

javascript - 事件处理程序绑定(bind)到匿名函数与命名函数

我知道.on()与jQuery一起存在并且.bind()不应该在未来使用,考虑到我有jQuery版本大于或等于1.7。我想知道的是:使用.bind()将匿名函数或命名函数附加到事件处理程序之间有什么区别吗?示例://Anonymousfunction$(".warning").bind("click",function(){alert("Hello");});//Namedfunction$(".warning").bind("click",foo);functionfoo(){alert("Hello");}假设我的页面中有100个div类warning。函数.bind()会将一个新

javascript - knockout 可见绑定(bind)不起作用

我有一个非常简单的View模型:varViewModel=function(){this.showRow=ko.observable(false);this.toggleVisibility=function(){if(this.showRow==true){this.showRow=false;}else{this.showRow=true;}alert('showRowisnow'+this.showRow);//onlyherefortesting};};同样简单的标记:ToggleSomeText我的问题是,当点击链接时,警告框显示(显示正确的值-true/false)但是,t