简体   繁体   中英

Error Binding strings with Angular 1.5 components

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>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM