We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Angular template with controller as vm without $scope

Hello,

I am trying to add ng-template column to the grid, with click action. It works fine with $parent referring to controller's scope. However I cannot figure out, is it possible to use Controller-As angular pattern?

Here is my simple example:
http://jsplayground.syncfusion.com/3ulkqblh


 <script type="text/ng-template" id="actionTemplate1">
        <span ng-click='$parent.alertPerScope(data.Color)'> {{"click me: "+ data.Color}}  //WORKS
  </span>
    </script>

      <script type="text/ng-template" id="actionTemplate2">
        <span ng-click='vm.alertPerVm(data.Color)'> {{"vm.click me: "+ data.Color}} //DOESNT WORK
  </span>
    </script>

3 Replies

VA Venkatesh Ayothi Raman Syncfusion Team January 25, 2016 12:34 PM UTC

Hi Ricardas,
Thanks for Contacting Syncfusion Support.
We have analyzed and achieved your query.
You can able to use Controller-As angular pattern In grid but the problem is, if you have directly accessed a Child Scope controller named “vm” in your code snippet because scope is only created for grid. Templates are used inside grid, it is like a child scope and grid is a parent scope.
We suggest you to use parent scope to access a click option through Controller as “vm” and use code like below:

<script type="text/ng-template" id="actionTemplate2">
<span ng-click='$parent.vm.alertPerVm(data.Color)'>{{"vm.click me: "+ data.Color}}
</span>
</script>

Try the above solution, still If you are facing the same issue, kindly share the issue reproducing sample.
Regards,
Venkatesh Ayothiraman.


RI Ricardas January 25, 2016 03:31 PM UTC

Great, it's working! Many thanks!


GV Gowthami V Syncfusion Team January 26, 2016 04:24 AM UTC

Hi Ricardas,
 
We are happy to hear that your has been resolved.
 
Get back to us if you need further assistance.
 
Regards,
 
Gowthami V.

Loader.
Live Chat Icon For mobile
Up arrow icon