$scope变量从一个函数传递到另一个函数
$scope variable passing from one function to another
我的角度控制器的功能看起来像:
$scope.selectinteresteduser= function(Id){
$scope.selecteduserid=Id;
}
$scope.sendMessageToEmployeer = function($scope.selecteduserid) {
alert($scope.selecteduserid);
}
我想将$scope.selecteduserid的值传递给sendMessageToEmployer函数。怎么做?
您需要通过如下定义和调用函数,将id作为参数传递给函数:
$scope.sendMessageToEmployeer = function(id) {
alert(id);
}
$scope.sendMessageToEmployeer($scope.selecteduserid);
无需将其作为参数传递。selecteduserid
已可用于控制器中的所有功能。
$scope.sendMessageToEmployeer = function() {
alert($scope.selecteduserid);
}
// execute function
$scope.sendMessageToEmployeer();
如果您需要从模板调用函数,请这样做;
$scope.sendMessageToEmployeer = function(id) {
alert(id);
}
基于模板的
<button type="button" ng-click="sendMessageToEmployeer(selecteduserid)"></button>
如果你想学习,请阅读Angular文档,特别是Angular Concept。@https://docs.angularjs.org/guide/concepts.
使用$scope指定您可以在控制器中全局访问其元素。您可以直接作为$scope.selecteduserid访问它无需将其作为参数传递。请提高基础知识。
相关文章:
- 创建一个类似链接的按钮,并通过Javascript函数打开一个新的弹出窗口
- 我可以在json对象中添加一个函数吗
- Javascript使函数一个接一个地执行
- 是JavaScript中的函数一个对象
- 两个几乎相等的jQuery函数;一个适用于IE,一个不适用于IE
- 两个Javascript函数一个window.onload=Custom.init;和一个window.onload=f
- 使javascript加载函数一个接一个地执行
- 如何通过两个嵌套的匿名函数(一个带有超时的事件处理程序)传递变量
- 为什么我不能让两个jQuery函数一个在另一个里面呢?
- 给函数一个变量名,而不是它的值
- 如何使用嵌入函数(一个滚动页由Pete - peachananr)
- 是否有可能给JavaScript函数一个类型/类?
- 确保两个函数一个接一个地执行,其中第一个函数内部有一个异步调用
- 两个不同的ajax函数一个接一个调用返回相同的值
- jQuery第一次更改函数一个工作
- 给这个函数一个id
- 如何给回调函数一个值一个变量在特定时刻
- 使用回调使两个函数一个接一个地运行
- 两个函数(一个用php)是否可以用“;onclick”;
- 两个几乎相同的函数.一个函数用Queue进行排队.Jquery效果在queued函数上不起作用.为什么