[英]Differnce between $scope.Variable and $scope.Function in Angular?
[英]Passing $scope.Variable to another function to set the value in angular
所以說我有這個函數為$ scope賦值。
function Tasker($http,$scope,angularServiceMessageVariable)
{
angularServiceMessageVariable = "some data";
}
我這樣稱呼它
function RunLockExpirationNotificationService($scope, $http, $spinner, $actions) {
$scope.runService = function () {
Tasker($http,$scope,$scope.LockExpirationNotificationServiceMessage);
};
}
我得到未定義的angularServiceMessageVariable,這基本上是我傳遞給該方法的$ scope.variable。 有人可以告訴我我在做什么錯。 我需要在另一個函數中設置作用域變量的值。 我嘗試了$ parse,但這給了我未定義的異常。
謝謝
而是將要添加到變量的變量名傳遞給作用域。 改成:
function Tasker($http,$scope,angularServiceMessageVariable)
{
$scope[angularServiceMessageVariable] = "some data";
}
和
function RunLockExpirationNotificationService($scope, $http, $spinner, $actions) {
$scope.runService = function () {
Tasker($http,$scope,'LockExpirationNotificationServiceMessage');
};
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.