angularjs - ng-flow.js, how to display responsed JSON data in HTML or controller -
i'm using ng-flow, script named ng-flow-standalone.js here: https://github.com/flowjs/ng-flow
my concept when user adding new item, upload field showing , once photo uploaded additional form fields showing e.g. title, description.
in code, app create product_id, image_id , saving file. once saving process complete, return product_id, image_id , etc in json format. html, hidden form fields displayed once product_id defined.
i see json responded server in console log not know how display in html or angular controller. can't see how-to in docs , demo. can me?
thanks
example code:
.. <script src="/assets/js/ng-flow-standalone.js"></script> .. <div class="row"> <div class="col-md-4" flow-init="{target:'upload_image.json'}" flow-file-added="!!{png:1,gif:1,jpg:1,jpeg:1}[$file.getextension()]"> <div class="panel panel-default"> <div class="panel-heading"> <h3 class="panel-title">photos</h3> </div> <div class="panel-body"> <div class="row"> <div ng-repeat="file in $flow.files"> <div class="col-md-3"> <div class="thumbnail"> <img flow-img="file" /> </div> </div> </div> </div> <div> <span class="btn btn-primary" flow-btn flow-files-submitted="$flow.upload()">upload</span> </div> </div> </div> </div> <div class="col-md-8" ng-show="{{ xxx.product_id }}"> <form class="panel panel-default form-horizontal"> <div class="panel-heading"> <h3 class="panel-title">infomation</h3> </div> <div class="panel-body"> <div class="form-group"> <label class="col-sm-2 control-label">title</label> <div class="col-sm-6"> <input name="name" type="text" class="form-control" required> </div> <div class="col-sm-4"></div> </div> <div class="form-group"> <label class="col-sm-2 control-label">description</label> <div class="col-sm-6"> <textarea class="form-control" rows="3" required></textarea> </div> <div class="col-sm-4">write useful info e.g. appearance, purpose , recommendations</div> </div> </div> <div class="panel-footer"> <input type="hidden" name="product" value="{{ xxx.product_id }}"> <button type="submit" class="btn btn-primary">save changes</button> </div> </form> </div> </div>
notice @ "xxx.product_id", xxx don't know, may somehting $flow.filesuccess.message.product_id.
solutions: using callback method in controller recommended aidas
$scope.$on('flow::filessubmitted', function (event, $flow, flowfile) products.save($scope.product) .$promise.then(function(result) { $scope.product = result; if ($scope.product.id) { $flow.opts.target = apiurl + '/products/' + $scope.product.id + '/images'; $flow.upload(); } }); });
you can't access success message directly, can access callback.
flow-file-success=" ... properties '$file', '$message' can accessed ... "
in html:
<div flow-file-success="success($message)">...
success
- should method defined in controller. assign message scope, or use in other way.
Comments
Post a Comment