最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Angular: passing data to directive during compile - Stack Overflow

programmeradmin3浏览0评论

Trying to do something like this:

var data = {some: 'data'}

var subponent = $pile('<div ponent-' + ponentName + ' ng-model="'+data+'"></div>')($scope);

$element.find('.container').html( subponent[0] );

I get error:

Error: [$parse:syntax] Syntax Error: Token 'Object' is unexpected, expecting []] at column 9 of the expression [[object Object]] starting at [Object]]

Trying to get this data to the link scope. Is there a way I should be going about passing the data to the directive scope?

Trying to do something like this:

var data = {some: 'data'}

var subponent = $pile('<div ponent-' + ponentName + ' ng-model="'+data+'"></div>')($scope);

$element.find('.container').html( subponent[0] );

I get error:

Error: [$parse:syntax] Syntax Error: Token 'Object' is unexpected, expecting []] at column 9 of the expression [[object Object]] starting at [Object]]

Trying to get this data to the link scope. Is there a way I should be going about passing the data to the directive scope?

Share Improve this question edited Jan 12, 2015 at 4:49 PSL 124k21 gold badges256 silver badges243 bronze badges asked Jan 12, 2015 at 4:42 user240993user240993 1
  • ng-model="'+data.some+'"????? – Bhojendra Rauniyar Commented Jan 12, 2015 at 4:47
Add a ment  | 

1 Answer 1

Reset to default 8

ng-model expression must be a property whose value can be set. So you would need to do something like.

$scope.data = {some: 'data'};// Set a property on the scope

/*Bind data to the ng-model*/
var subponent = $pile('<div ponent-' + ponentName + ' ng-model="data"></div>')($scope);

In your case you are trying to add an object to the string which will convert the object to its string representation i.e [object Object]. So what you need is to set a property name (existing/non-existing) on the scope.

发布评论

评论列表(0)

  1. 暂无评论