Angularjs onload调用控制器中的函数以在html中设置值 $rootScope.customerName=null; var getCustomer=函数(){ getCustomerById($scope.customerId)。然后( 功能(数据){ $scope.derals.customerName=data.customerName; $scope.deralers.customerNameLabel=data.customerName+“”; $rootScope.customerName=''+$scope.derals.customerNameLabel; } } ); }; getCustomer(); {{customerName}}

Angularjs onload调用控制器中的函数以在html中设置值 $rootScope.customerName=null; var getCustomer=函数(){ getCustomerById($scope.customerId)。然后( 功能(数据){ $scope.derals.customerName=data.customerName; $scope.deralers.customerNameLabel=data.customerName+“”; $rootScope.customerName=''+$scope.derals.customerNameLabel; } } ); }; getCustomer(); {{customerName}},angularjs,Angularjs,onload我在controller中调用一个函数来设置html中的值,但它不起作用,在函数内部,值被设置为“abc”,而当我在html中调用它时,它只是未定义。需要帮助。如果值未更新,您必须手动调用摘要周期,即$Scope.$apply() $rootScope.customerName = null; var getCustomer = function () { Service.getCustomerById($scope.customerId).then(

onload我在controller中调用一个函数来设置html中的值,但它不起作用,在函数内部,值被设置为“abc”,而当我在html中调用它时,它只是未定义。需要帮助。

如果值未更新,您必须手动调用摘要周期,即$Scope.$apply()

 $rootScope.customerName = null;

    var getCustomer = function () {
      Service.getCustomerById($scope.customerId).then(
        function (data) {
          $scope.dealers.customerName = data.customerName;
          $scope.dealers.customerNameLabel = data.customerName + ' ';
          $rootScope.customerName = ' '+ $scope.dealers.customerNameLabel;
        }
        }
      );
    };

 getCustomer();

<div>{{customerName}}</div>
$rootScope.customerName=null;
var getCustomer=函数(){
getCustomerById($scope.customerId)。然后(
功能(数据){
$scope.derals.customerName=data.customerName;
$scope.deralers.customerNameLabel=data.customerName+“”;
$rootScope.customerName=''+$scope.derals.customerNameLabel;
$Scope.$apply();
}
}
);
};
getCustomer();
{{customerName}}

Can u post onload function to GetCustomer is my onload function,该值未设置为hi,如果我给$scope,则该值正在填充。
$rootScope.customerName = null;
    var getCustomer = function () {
      Service.getCustomerById($scope.customerId).then(
        function (data) {
          $scope.dealers.customerName = data.customerName;
          $scope.dealers.customerNameLabel = data.customerName + ' ';
          $rootScope.customerName = ' '+ $scope.dealers.customerNameLabel;
            $Scope.$apply();
        }
        }
      );
    };

 getCustomer();

<div>{{customerName}}</div>