1

I am trying to bind a string through the html of an angular 1.5 component. I am getting an error message that says:

Error: [$compile:nonassign] Expression ''My Title'' in attribute 'title' used with directive 'selectList' is non-assignable!

This is the html where I am calling the component:

index.html

<select-list title="'My Title'"></select-list>

and the component:

export var selectListComponent = {
    bindings: {
        title: "="
    },
    templateUrl: 'path/selectList.html',
    controller: selectListController
};

and the component html:

<div>{{$ctrl.title}}</div>

1 Answer 1

2

You're using two way binding and providing a constant string as the binding target.

You would need to change your component to use:

export var selectListComponent = {
    bindings: {
        title: "@"
    },
    templateUrl: 'path/selectList.html',
    controller: selectListController
};

The @ will evaluate the value it is passed (a string in this case) and then perform one-way binding to the directive scope.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Simon, at first I was trying it with '<' for the one-way binding but I guess that is not for primitive data types? marked as answer though, was exactly what was wrong

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.