没有从控制器到html视图获取$ rootScope.updatedata

时间:2018-05-16 15:03:37

标签: angularjs json spring

我正在尝试使用{j}的$rootScope.updatedata从控制器获取$rootScope到视图。当我将从服务器响应中获取的数据传递给视图时,数据为空。从控制器,数据有一个值。这是片段

app.controller("updateCtrl",["$scope","$rootScope","$location","$cookies","$http",
                            function($scope,$rootScope,$location,$cookies,$http){
    getUserDetails: function (email) {
            $http({
                method: 'GET',
                url: '/updateprofile',
                params: {email: email}
            }).then(function successCallback(response) {
                if (response.status == 204) {
                } else if (response.status == 200) {


                    alert("email24 "+response.data); //this returns an object
                    $rootScope.updatedata = response.data; //passing to the view                }
            }, function errorCallback(response) {
                alert(JSON.stringify(response));
            });
        }
    }

这是我在视图中获取它的方式

<input formcontrolname="firstName" value="{{updatedata.email}}" />

spring controller snippets

@RequestMapping(value = {"/updateprofile"}, method = RequestMethod.GET, headers = "Accept=application/json") 
    public ResponseData<Client> updateByEmail( @RequestParam("email") String email) {

这是我的挑战

1 个答案:

答案 0 :(得分:0)

在这种情况下使用app.controller("updateCtrl",["$scope","$location","$cookies","$http", function($scope,$location,$cookies,$http){ $scope.updatedata = { email: "", //rest of your fields }; getUserDetails: function (email) { $http({ method: 'GET', url: '/updateprofile', params: {email: email} }).then(function successCallback(response) { if (response.status == 204) { } else if (response.status == 200) { alert("email24 "+response.data); //this returns an object $scope.updatedata.email = response.data.email; //populate rest of the fields } }, function errorCallback(response) { alert(JSON.stringify(response)); }); } } 对您没有帮助。一般来说,尽量避免使用它,这是一种不好的做法。尝试这样的事情:

<div id="bubble"></div>
<div id="buttonHide"><button>Hide</button></div>
<div id="buttonShow"><button>Show</button></div>

d3.select("#bubble")
    .append("svg")
    .append("g")
    .append("circle")
    .attr("class", "bubble")
    .attr("transform", "translate(100, 100)")
    .attr("r", 50)
    .attr("fill", "black");

d3.select("#buttonHide").on("click", function() {
    d3.select(".bubble").transition().attr('visibility', 'hidden').duration(1000);
});

d3.select("#buttonShow").on("click", function() {
    d3.select(".bubble").transition().attr('visibility', 'visible').duration(1000);
});