TypeScript AngularJS component modal - this.$modalInstance.dismiss is not a function?

后端 未结 1 939
醉梦人生
醉梦人生 2021-01-28 13:54

I\'ve turned one of my user data entry forms into a uib-modal, but I get when I attempt to close the modal from the \"cancel\"button, I get this error: this.$modalInstance

相关标签:
1条回答
  • 2021-01-28 14:12

    When using the component property of the $uibModal.open method, use bindings instead of local injection:

    app.component("fringeEdit", {
        controller: "FringeEditController",
        templateUrl: "/template/fringeEditTemplate.html",
        bindings: { close: "&" }
    }); 
    

    Then use the bindings in the controller:

    dismiss() {
      this.close({$value: "closed"});
    }
    

    From the Docs:

    $uibModal's open function

    options parameter

    • component (Type: string, Example: myComponent) - A string reference to the component to be rendered that is registered with Angular's compiler. If using a directive, the directive must have restrict: 'E' and a template or templateUrl set.

      It supports these bindings:

      • close - A method that can be used to close a modal, passing a result. The result must be passed in this format: {$value: myResult}

    For more information, see

    • UI-Bootstrap Modal Directive API Reference
    0 讨论(0)
提交回复
热议问题