Home > Software design >  How to prevent a component from starting/rendering when the required parameters are not filled corre
How to prevent a component from starting/rendering when the required parameters are not filled corre

Time:01-21

Say I have a component and I have bindings that are not optional, like so

angular.module("foo").component("fooComp", {
    bindings: {
      notOpt: "<",
    },
    templateUrl: "...",
    controllerAs: "...",
    controller: [fooCtrl],
  });
  function fooCtrl() {
    const $vm = this;

    $vm.$onInit = onInit;

    function onInit() {
      // ...
    }

  }

Is there a way that I can prevent the component from rendering without the help of a flag and ngIf? Something like a self destroy?

Thanks

CodePudding user response:

Try "Conditional render" :D I leave the site which tells you how to do it. React and Angular are both JavaScript. You can do what you need with this idea :D

https://www.digitalocean.com/community/tutorials/7-ways-to-implement-conditional-rendering-in-react-applications

If my answer helped you, pls select my answer :D

CodePudding user response:

What I ended up doing is just removing the element with $element.remove() and then also destroying the scope with $scope.destroy().

  •  Tags:  
  • Related