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?
-
ng-model="'+data.some+'"
????? – Bhojendra Rauniyar Commented Jan 12, 2015 at 4:47
1 Answer
Reset to default 8ng-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.