taiwoorogbangba taiwoorogbangba - 1 year ago 40
AngularJS Question

Print from the frontend using AngularJS

I'm currently working on an AngularJS project and I would like to print option selected on a drop down list together with input data that has been entered by the user without using the backend. How can this be done using AngularJS? Any help?

Answer Source

I believe you wanted something like Prefix + Name, her https://jsfiddle.net/datachand/szc550yb/3/

<div ng-controller="UserCtrl as vm">
   <select ng-model="vm.prefix">
     <option value="Mr.">Mr.</option>
     <option value="Ms.">Ms.</option>
   <input type="text" ng-model="vm.name" placeholder="Enter your Name">
   <button ng-click="vm.submit()">

A controller is needed at any case, even if it's empty:

angular.module('app', []);

function UserCtrl ($log) {
    var vm = this;

    vm.submit = function () {
        $log.log(vm.prefix, vm.name);
        $window.location.href = "https://towhateverurl" + "?prefix=" + vm.prefix +"&name=" + vm.name;

UserCtrl.$inject = ['$log'];

angular.module('app').controller('UserCtrl', UserCtrl);

I hope this is what, is required.