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.
Unfortunately, activation email could not send to your email. Please try again.

Angular template with controller as vm without $scope

Thread ID:

Created:

Updated:

Platform:

Replies:

121766 Jan 22,2016 09:24 AM Jan 25,2016 11:24 PM JavaScript 3
loading
Tags: ejGrid
Ricardas
Asked On January 22, 2016 09:24 AM

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>

Venkatesh Ayothi Raman [Syncfusion]
Replied On January 25, 2016 07:34 AM

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.

Ricardas
Replied On January 25, 2016 10:31 AM

Great, it's working! Many thanks!

Gowthami V [Syncfusion]
Replied On January 25, 2016 11:24 PM

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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;