简体   繁体   中英

Update dashboard from the dropdown choice in a angularjs application

I have an angularjs application that have a dashboard that is built from services. These Services are called passing a parameter like a user ID.

In this dashboard we have a dropdown that offer a user change, and when this happens i have to update all my services and dashboard.

How can i do that? Thanks in advance

See this https://www.codementor.io/angularjs/tutorial/create-dropdown-control and and then register a listener to the 'user change' field like in this thread Angular: Update service and share data between controllers

You can also use $scope.$watch() ( How do I use $scope.$watch and $scope.$apply in AngularJS? , http://jimhoskins.com/2012/12/17/angularjs-and-apply.html )

In general use the standard angular controller for this. In the following the text in the input-fields First Name and Last Name is set to John Doe

 <div ng-app="myApp" ng-controller="myCtrl">

First Name: <input type="text" ng-model="firstName"><br>
Last Name: <input type="text" ng-model="lastName"><br>
<br>
Full Name: {{firstName + " " + lastName}}

</div>

<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
    $scope.firstName = "John";
    $scope.lastName = "Doe";
});
</script> 

http://www.w3schools.com/angular/angular_controllers.asp

In the controller for the dropdown menu, parse the new user id when 'user change' is clicked and execute the changes in dashboard you want (change name in textfield, update services (see link above),...) depending on the new user id.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM