A
A
Abc Edc2015-06-17 13:48:54
Angular
Abc Edc, 2015-06-17 13:48:54

What does $parse.assign do in angular?

I decided to sort out the library with the checker directive
and immediately questions

function postLinkFn(scope, elem, attrs) {
    $compile(elem)(scope);
    var getter = $parse(attrs.checklistModel);
    var setter = getter.assign;

What happens in the last two lines?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Osher, 2015-06-17
@gleber1

https://docs.angularjs.org/api/ng/service/$parse

var getter = $parse('user.name');
var setter = getter.assign;
var context = {user:{name:'angular'}};
var locals = {user:{name:'local'}};

expect(getter(context)).toEqual('angular');
setter(context, 'newValue');
expect(context.user.name).toEqual('newValue');
expect(getter(context, locals)).toEqual('local');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question