user1217974
user1217974

Reputation: 154

angularjs $compile not working for custom template

im trying to render a custom template using the $compile but i keep getting

unrecognized expression: {{senddata}}

My code is like below

app.controller('MainCtrl', function ($scope, ngDialog,$http,$compile){
      $scope.afterasset = function (selectedValues) {
           $scope.senddata = 'testdata';
           var data = $compile( '{{senddata}}' )( $scope );
      }
}

Any idea guys ? thanks :)

Upvotes: 0

Views: 1530

Answers (1)

Narek Mamikonyan
Narek Mamikonyan

Reputation: 4611

Its does't work because $compile provider need a HTML string with element tags or wraped jQlite element.

Try -

app.controller('MainCtrl', function ($scope, ngDialog,$http,$compile){
      $scope.afterasset = function (selectedValues) {
           $scope.senddata = 'testdata';
           var data = $compile( '<p>{{senddata}}</p>' )( $scope );
      }
}

Upvotes: 1

Related Questions