AngularJS 使用$scope.(参数)
AngularJS Use $scope.(parameter)
我有 2 个buttons
和 2 个contenteditable div
。当我单击一个button
时,我传递一个参数。现在在控制器中,我有一个 $rootScope.$on() 函数,它附加到contenteditable div
中,所以我想在 $rootScope.$on()
方法中编写$scope.paramter
,而不是参数,我想把我传递的值作为参数。
例:
<button type="button" ng-click="open('textModel')">Emojis</button>
<div contenteditable="true" ng-model="textModel"></div>
<button type="button" class="btn btn-default" ng-click="open('textModel2')">Emojis</button>
<div contenteditable="true" ng-model="textModel2"></div>
控制器内部
$rootScope.$on('selectedCode', function(event, args){
console.log(btnid); //btnid has the value textModel or textModel2 depending on the button clicked
$scope.btnid += 'Hello'; //I want that instead of btnid, textModel gets appended
});
现在在控制器中我想把它写成$scope.textModel += 'Hello';
而不是$scope.parameter
,所以当我按下第一个按钮时,ng-model 作为 textModel 的contenteditable div
被附加,当我按下第二个按钮时,ng-model 作为 textModel2 的contenteditable div
被附加
请帮忙
使用括号表示法按变量名称访问属性:
$rootScope.$on('selectedCode', function(event, args) {
$scope[btnid] += 'Hello';
});
相关文章:
- $location.search() - 如何在 $scope.$watch 函数中使用作用域中的参数
- 将传递的函数参数附加到控制器内的$scope
- 将$scope对象作为参数提供给$digest中的观察者背后的逻辑
- AngularJS 使用$scope.(参数)
- Angular 的控制器方法如何使$scope可用于我的函数参数
- $scope函数参数从何而来
- AngularJS $scope.$watch Jasmine 测试中未定义的回调函数参数
- 对 $scope.$watch 的第一个参数的混淆
- Backbone.BabySiter内部参数-Javascript Scope
- 带有$state.go和$scope的参数
- 自定义AngularJS过滤器忽略我的参数并接收一些其他scope.data
- 为什么我们要将函数参数传递到$scope$申请
- 将参数传递给回调函数:Scope issue
- 使用Restangular并尝试从$scope中为一个var设置多个参数
- 将函数参数传递给$scope.$apply
- Angularjs, $scope参数是如何在幕后工作的
- 功能的外包实现包含$http、$scope和其他参数
- $stateParams没有传递$scope中的参数.美元的方法
- 无法将变量/ng-model绑定变量作为参数传递给$scope工厂函数
- Angularjs将$scope方法作为参数传递给另一个$scope方法