0

I have the following angular:

angular.module("app.components", []);
angular.module("app", [
    "app.components"
]);

angular.module("app.components")
    .component('testWidget', {
        templateUrl: '/Widgets/TestWidget/Templates/TestWidget.template.html',
        bindings: {
            something: "="
        },
        controller: function () {
            var ctrl = this;
            // ctrl has nothing on it
        }
    });

<div ng-app="app">
    <test-widget something="Shoopy"></test-widget>
</div>

but the something is not part of the object (this) in the controller. what have i missed?

2
  • what is the error you are getting? Commented Apr 29, 2018 at 19:30
  • No error, it's just that ctrl.something does not exist? Commented Apr 29, 2018 at 23:26

2 Answers 2

1

two-way binding (expects a parent scope property to watch for value changes):

bindings: {
    something: "="
}

A parent controller would need to set the property:

$scope.Shoopy = "hello world"

For parameter bindings use the following:

string value binding:

bindings: {
    something: "@"
}
Sign up to request clarification or add additional context in comments.

Comments

0

you forgot controllerAs since you're using this instead of $scope

try this

angular.module("app.components")
    .component('testWidget', {
        templateUrl: '/Widgets/TestWidget/Templates/TestWidget.template.html',
        bindings: {
            something: "="
        },
        controllerAs: "ctrl",
        controller: function () {
            var ctrl = this;
            // ctrl has nothing on it
        }
    });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.