小编gvl*_*lax的帖子

foo()和function()之间的区别{foo(); }

使用匿名函数包装函数有什么好处吗?我的意思是一个特例:

function asyncFuntion(callback) {
    setTimeout(callback, 6000);
};

asyncFuntion(function() {
    console.log('Calling after 6 s.');
});   
Run Code Online (Sandbox Code Playgroud)

以及包装功能:

function asyncFuntion(callback) {
    setTimeout(function() {
        callback();
    }, 6000);
};

asyncFuntion(function() {
    console.log('Calling after 6 s.');
});
Run Code Online (Sandbox Code Playgroud)

在这两种情况下输出都是相同的.那有什么区别吗?第二个版本是我发现的学习js.我知道当我们需要闭包时这样的表格很有用但是在这里?

javascript

8
推荐指数
3
解决办法
250
查看次数

输入无线电ng模型毕竟没有更新

我试图解决一个难题,为什么输入[无线电]控件的ng模型没有像我期望的那样设置.加载页面时,所有无线电都会正确启动.单击不同的控件会更改radioVal变量 - 其值将在页面中呈现.

问题是看起来它只发生在DOM中.当我调试代码时,$scope.radioVal它始终是相同的......隔离的范围modalDialog不包含radioVal属性.

无线电在哪个范围内ng-model创建?它是一个不同的例子吗?


工作代码可以在jsfiddle上找到.


我的HTML代码是:

<div ng-app = "app"> 
 <div ng-controller="mainCtrl">         
   <a ng-click="showModalDlg()">Click me</a>
   <br/><br/>
   <modal-dialog show="showModal" action="actionFun">                        
    <form>
      <input type="radio" ng-model="radioVal" value="1">One<br/>
      <input type="radio" ng-model="radioVal" value="nothing changes me">Two<br/>
      <input type="radio" ng-model="radioVal" value="3">Three<br/>
          <br/><br/>
          The model changes in the DOM as expected: <b>radioVal = {{radioVal | json}}</b>
          <br/>
          but by pressing the Action button you can see that the model has not been modified. 
    </form>                        
    <a class="button" action>Action</a> …
Run Code Online (Sandbox Code Playgroud)

javascript radio-button angularjs

3
推荐指数
1
解决办法
1731
查看次数

标签 统计

javascript ×2

angularjs ×1

radio-button ×1