简体   繁体   English

从 angularjs 应用程序的下拉选项中更新仪表板

[英]Update dashboard from the dropdown choice in a angularjs application

I have an angularjs application that have a dashboard that is built from services.我有一个 angularjs 应用程序,它有一个由服务构建的仪表板。 These Services are called passing a parameter like a user ID.这些服务被称为传递参数,如用户 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请参阅此https://www.codementor.io/angularjs/tutorial/create-dropdown-control ,然后将侦听器注册到“用户更改”字段,如该线程Angular:更新服务并在控制器之间共享数据

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 )你也可以使用$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在下面的输入字段中的文本名字姓氏设置为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 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.在下拉菜单的控制器中,在单击“用户更改”时解析新用户 ID,并根据新用户在仪表板中执行所需更改(更改文本字段中的名称、更新服务(参见上面的链接)...)用户身份。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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