如何从Angularjs中的指令更新控制器中的变量(ControllerAs语法)?

时间:2017-01-06 00:22:18

标签: angularjs angularjs-directive angularjs-controlleras

我有import javafx.application.Application; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.ListView; import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; import javafx.scene.layout.Priority; import javafx.scene.layout.StackPane; import javafx.stage.Stage; public class Main extends Application { public void start(Stage stage) throws Exception { // I've tried with this as a VBox, no effect. GridPane main = new GridPane(); main.setGridLinesVisible(true); main.setHgap(5); main.setVgap(10); // Meant to change what content is displayed in the actual program. HBox menu = new HBox(); // menu.setMaxWidth(Double.MAX_VALUE); menu.setAlignment(Pos.CENTER); main.add(menu, 0, 0); GridPane.setHgrow(menu, Priority.ALWAYS); menu.getChildren().addAll(new Button("Button 1"), new Button("Button 2"), new Button("Button 3"), new Label("Hello world!")); // Changes often. GridPane content = new GridPane(); main.add(content, 0, 1); // Options for the displayed content, changes the StackPane displayed below in my actual program. HBox submenu = new HBox(); // submenu.setMaxWidth(Double.MAX_VALUE); submenu.setAlignment(Pos.CENTER); content.add(submenu, 0, 0); GridPane.setHgrow(submenu, Priority.ALWAYS); submenu.getChildren().addAll(new Button("Button A"), new Button("Button B"), new Button("Button C"), new Label("Hello world!")); // This is a custom class extended by StackPane in my actual program. Is often over overlayed with another transparent StackPane (not relevant to the problem). StackPane subcontent = new StackPane(); // subcontent.setMaxHeight(Double.MAX_VALUE); // subcontent.setMaxWidth(Double.MAX_VALUE); content.add(subcontent, 0, 1); // This was meant to be a TabPane in my actual program but this has the same outcome that won't fill the rest of the window height. ListView<String> list = new ListView<>(); // list.setMaxHeight(Double.MAX_VALUE); // list.setMaxWidth(Double.MAX_VALUE); ObservableList<String> items = FXCollections.observableArrayList(); list.setItems(items); subcontent.getChildren().add(list); for(int i=0; i<100; i++) { items.add("# "+i); } GridPane.setVgrow(content, Priority.ALWAYS); GridPane.setVgrow(subcontent, Priority.ALWAYS); Scene scene = new Scene(main, 900, 550); stage.setScene(scene); stage.show(); } public static void main(String[] args) { launch(args); } } 指令:

dropzone

function dropzone() { return { restrict: 'C', link: function(scope, element, attrs) { var config = { url: 'http://192.168.1.114:8080/api/files', maxFilesize: 100, paramName: "file", maxThumbnailFilesize: 10, parallelUploads: 1, autoProcessQueue: true }; var eventHandlers = { 'success': function (file, response) { } }; dropzone = new Dropzone(element[0], config); angular.forEach(eventHandlers, function(handler, event) { dropzone.on(event, handler); }); } } } 事件处理程序中的response是上传的文件ID。

我想在我的success中保留所有上传文件的ID列表:

uploadFileFormCtrl

这适用于特定的控制器,即function uploadFileFormCtrl() { var _this = this; _this.fileIds = []; };

uploadFileFormCtrl as uploadFile

但是,我有多个不同的 'success': function (file, response) { scope.uploadFile.fileIds.push(Number(response)); scope.$apply(); } (例如:controllersuploadFile等),其中包含uploadImage文件上传器,因此我无法添加指令中的特定控制器名称。

指令和控制器如何相互通信才能实现这一目标?

0 个答案:

没有答案