angularjs - Angular JS: scope not correct when calling a function dynamically? -
i'm new angular js. in plunkr, have typeahead works when have typeahead in html markup. however, when dynamically generate html inside directive, typeahead no longer works.
code here: http://plnkr.co/edit/kdrxptyanptmka7zukkm?p=preview
and take 1 step further, when pass in function, still not work: http://plnkr.co/edit/jqn913hjxuvsfazxaqt7?p=preview
it not trivial problem trying solve here, i'm afraid. bumping scoping issue. typeahead
directive evaluates expression (city city in cities($viewvalue)
here) in scope of dom element on placed. way written wrapper directive makes expression evaluated in directive's scope isolated , doesn't "see" controllers scope.
the number of ways around simplest 1 link $compiled-ed element in scope $parent of directive scope:
var linkedinput = $compile(inputhtml)(scope.$parent);
here working plunk: http://plnkr.co/edit/flfwiknqirbnesmjzbgj?p=preview
the other alternative loose isolated scope , "manually" take care of 2-way data binding $parse
service.
Comments
Post a Comment