locked
Understanding JavaScript Logic RRS feed

  • Question

  • User-410261901 posted

    I have inherited an angular.js project and I am trying to understand the flow of the code and what happens.  I am analyzing this piece of code (I removed some of the lines, but the base elements remain).

    Do I understand properly that when the pop-up is displayed this code will accept the user input, then when the user presses the Complete button the DCila method will run?

    $mdDialog.show({

    parent: parentEl,

    scope: $scope,

    preserveScope: true,

    targetEvent: $event,

    disableParentScroll: false,

    template:

    '<md-dialog aria-label="">' +

      '<md-toolbar>' +

      '</md-toolbar>' +

      '<md-dialog-content ng-cloak>' +

    '<div class="md-dialog-content">' +

      '<form ng-submit="$event.preventDefault()">' +

    '<md-autocomplete ' +

    '</md-autocomplete>' +

      '</form>' +

    '</div>' +

      '</md-dialog-content>' +

      '<md-dialog-actions>' +

    '<md-button aria-label="Complete" ng-click="ctrl.finish($event)">Complete</md-button>' +

      '</md-dialog-actions>' +

    '</md-dialog>',

    controller: DCila,

    controllerAs: 'ctrl'                        

    });

    Thursday, December 28, 2017 12:10 AM

Answers

  • User-1838255255 posted

    Hi HiThereltsClaire,

    According to your description, i checked your code, the logical of the code will show the dialog, you could input the text in it, but about how to trigger the click event, we usually use the following method: ng-click="functionname()". I hope you could run it in your side, check if meet the issue. 

    For more details, please check the following tutorial:

    $mdDialog API Documentation: 

    https://material.angularjs.org/latest/api/service/$mdDialog 

    Best Regards,

    Eric Du 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 28, 2017 8:01 AM

All replies

  • User-1838255255 posted

    Hi HiThereltsClaire,

    According to your description, i checked your code, the logical of the code will show the dialog, you could input the text in it, but about how to trigger the click event, we usually use the following method: ng-click="functionname()". I hope you could run it in your side, check if meet the issue. 

    For more details, please check the following tutorial:

    $mdDialog API Documentation: 

    https://material.angularjs.org/latest/api/service/$mdDialog 

    Best Regards,

    Eric Du 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 28, 2017 8:01 AM
  • User-474980206 posted

    you should read the angular documentation. angular uses the MVC pattern, with routers, controllers, and views. the view engine is a template engine. 

    your sample code is using the new controllerAs syntax, that changes how scope is handled. but you are correct DCila is the controller that will be called. You should read up n the new controllerAs syntax to better understand the binding.

    note: I'm not an angular developer (prefer react/redux instead), so only know enough angular to be dangerous.

    Thursday, December 28, 2017 5:54 PM