AngularJS function and $scope
AngularJS function and $scope
我在控制器中定义了如下函数:
var getTransactions = function(transactionType, partnerId) {
return loadTexts.getTransactionTexts(transactionType, partnerId).then(function (res) {
$scope.loadedTexts = res.data.Transactions;
});
};
另一个$scope函数正在调用它。现在,当我为res.data.Transactions
设置console.log时,一切都会按原样记录,但当我想将数据分配给$scope变量时,它根本不起作用。(load
功能后,$scope.loadedTexts
为空(
$scope.load = function() {
getTransactions($scope.TransactionTypeId, $scope.selectedPartner.Id);
};
有什么帮助吗?
代码:
app.controller("textsController", function ($scope, $http, autoComplete, loadTexts) {
$scope.selectedPartner = { "Name": "", "Id": null };
$scope.loadedTexts = [];
.. other functions are here ...
var getTransactions = function(transactionType, partnerId) {
return loadTexts.getTransactionTexts(transactionType, partnerId);
};
$scope.load = function () {
getTransactions($scope.transactionType, $scope.selectedPartner.Id).then(function(res) {
$scope.loadedTexts = res.data.Transactions;
});
};
});
在代码中,您显示的一切对我来说都很好。但是,请注意,您将对Transactions的引用存储在loadedText中。也许"Transactions"对象res.Data.Transactions在其他地方被清除了。您可以尝试复制对象,而不是指定引用(例如使用angular.copy(来测试这是否是原因。
相关文章:
- AngularJS:ng之后,重复$scope值未按预期更新
- $ionicplatform内的$scope不;不起作用
- Selenium WebDriver and JavaScript change
- 使用$scope方法时的ControllerAs语法
- 如何将ngrepeat下的ngmodel绑定到$scope
- 另一个if(!$scope.$$phase)$scope$apply()szenario-需要帮助才能通关
- 使用AngularJS Directive WHITOUT$scope创建一个动态html元素
- $scope变量被视为字符串AngularJs
- PHP and Javascript functions
- Javascript scope and self=this, _this=this, that=this
- module.exports scope and node-mysql
- javascript setInterval() and Variable Scope
- Javascript Scope and Closure,变量保持其值
- Getters and Setters on angular.extend $scope
- Inline SVG and HTML DOM Scope for .getElementById
- $scope and $rootscope confusion
- angular.toJson($scope.object) and JSON.stringify($scope.obje
- ng-repeat and $scope issue
- AngularJS function and $scope
- Working with $scope.$emit and $scope.$on