Why are my component bindings undefined in its controller?

前端 未结 9 1779
醉梦人生
醉梦人生 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 14:00

    The value for contactId is available on the $scope in your controller:

    var app = angular.module("test", []);
    app.component("test", {
      bindings: {
        "contactId": "<"
      },
      controllerAs: "model",
      controller: ($scope) => {
        var model = $scope.model;
        alert(`contact id from controller: ${model.contactId}`);
      },
      template: "
    Contact id from view: {{model.contactId}}
    " });

    Link to another version of your Plunker here.

提交回复
热议问题