Javascript 页面加载AngularJS时文本框绑定不起作用

Javascript 页面加载AngularJS时文本框绑定不起作用,javascript,angularjs,Javascript,Angularjs,我试图在页面加载时根据承诺值的结果设置textbox值。文本框上的值只有在我点击它然后退出时才会设置(就像模糊事件一样) 控制器 (function() { 'use strict' var newPurchasingCardController = function($scope, $rootScope, $filter, $window, $location, $timeout, requestService) { $scope.action

我试图在页面加载时根据承诺值的结果设置textbox值。文本框上的值只有在我点击它然后退出时才会设置(就像模糊事件一样)

控制器

(function() {
    'use strict'
    var newPurchasingCardController = function($scope, $rootScope, $filter, $window, $location, $timeout, requestService) {        

        $scope.actionTitle = "";            
        $scope.gin = "";
        $scope.fullName = "";
        $scope.workEmail = "";
        $scope.msg = "";            

        var getCurrentUserData = function () {

            var dfd = new $.Deferred();
            var queryUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/SP.UserProfiles.PeopleManager/GetMyProperties";
            $.ajax({
                url: queryUrl,
                method: "GET",
                headers: { "Accept": "application/json; odata=verbose" },
                success: onSuccess,
                error: onError,
                cache: false
            });

            function onSuccess(data) {
                dfd.resolve(data);                    
            }

            function onError(data, errorCode, errorMessage) {
                dfd.reject(errorMessage);
            }

            return dfd.promise();               
        }            

        var _init = function () {

            $scope.actionTitle = "New Card Request"

            var promise = getCurrentUserData();

            promise.then(function (data) {

                $.each(data.d.UserProfileProperties.results,function(i,property){
                    if(property.Key === "EmployeeNumber")
                    {
                        $scope.gin = property.Value;
                    }

                    if(property.Key === "FirstName")
                    {
                        $scope.fullName = property.Value;
                    } 
                    else if (property.Key === "LastName") {
                        $scope.fullName += " " + property.Value;
                    }

                    if(property.Key === "WorkEmail") {
                        $scope.workEmail = property.Value;
                    }
                    console.log(property.Key+":"+property.Value);               
                });
            }, function(error) {
                console.log("An error has occurred trying to get employee information." + error);
            });
        }

        $scope.$on('$viewContentLoaded', function(event)
        { 
            _init();
        });            
    }

    angular.module('myApp').controller('newPurchasingCardController', ['$scope', '$rootScope', '$filter', '$window', '$location', '$timeout', 'requestService', createnewPurchasingCardController]);
}());
在html视图中,我刚刚看到

HTML



我尝试过viewContentLoaded,但不起作用,实现这一点的好方法是什么?谢谢。

您将
angularjs
Jquery
混合在一起,这导致了所有问题

对get请求使用
$http
服务:


jQuery创建的承诺没有与AngularJS框架集成。AngularJS通过提供自己的事件处理循环来修改正常的JavaScript流。这将JavaScript分为经典和AngularJS执行上下文。只有在AngularJS执行上下文中应用的操作才会受益于AngularJS数据绑定、异常处理、属性监视等。
<input ng-model="gin" type="gin" class="form-control" id="gin" placeholder="GIN">
<input ng-model="fullName" type="name" class="form-control" id="name" placeholder="Name">
<input ng-model="workEmail" type="email" class="form-control" id="email" placeholder="Email">
var getCurrentUserData = function () {

        var queryUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/SP.UserProfiles.PeopleManager/GetMyProperties";
        $http({
            url: queryUrl,
            method: "GET",
            headers: { "Accept": "application/json; odata=verbose" },
            cache: false
        })
         .then(function(response) {
             $scope.gin = response.data.EmployeeNumber;
             // here set scope variables directly
         })
        .catch(function(response) {
           console.error('error', response.status, response.data);
         })
       .finally(function() {
           console.log("finally ");
        });

}