Why are my component bindings undefined in its controller?

前端 未结 9 1777
醉梦人生
醉梦人生 2021-01-31 13:22

I\'m writing a simple angular component. I\'m passing a parameter as a binding and display its value on the screen. All works fine: I can see the parameter being displayed on th

9条回答
  •  清酒与你
    2021-01-31 13:55

    For those using Directives, where Components are assumed, if bindings{} is specified it appears adding those same parameters to scope{} works:

    /*bindings: {
        modalInstance: '<',
        resolve: '<'
    },*/
    scope: {
        modalInstance: '<',
        resolve: '<'
    },
    

    *Discovered after I wrote the above that an additional scope parameter, foo, wasn't available on $scope until I assigned it from $scope.resolve. So I had to do this in $scope.init(): $scope.foo = $scope.resolve.foo. Not sure why. Guessing it has to do with my UI Bootstrap Modal + Directives usage

    This may be obvious for others but wasn't for me being relatively new to AnguluarJS.

    My problem was using Directives with UI-Bootstrap Modals which are compatible with Directives but designed and documented for use with Components.

提交回复
热议问题