1

I'm trying to use the ControllerAs in Template but result is blank. the construct of my controller is like:

app.controller("MyController",function(){
 this.result=getResult();
this.gridOptions={data:'result'};
});

I'm using this controller as:

<div ng-controller="MyController as myCtrl">
 <div ng-grid="myCtrl.gridOptions"></div>
</div>

Thanks.

1
  • 1
    Using this.gridOptions={data:'myCtrl.result'}; will limit the controller to one instance only, is there any way like inject or something I can use, which takes up the instance from creation part ie. <div ng-controller="MyController as myCtrl"> Commented Jul 25, 2014 at 5:55

2 Answers 2

1

Try

app.controller("MyController",function(){

    this.result=getResult();
    this.gridOptions={data:'myCtrl.result'};

});
Sign up to request clarification or add additional context in comments.

Comments

1

The compiler look up 'results' in the $scope

You must use the alias instead,

like this:

app.controller("MyController",function(){
 this.result=getResult();
this.gridOptions={data:'myCtrl.result'};
});

http://plnkr.co/edit/22qXbu?p=preview

1 Comment

thank you, using this.gridOptions={data:'myCtrl.result'}; will limit the controller to one instance only, is there any way like inject or something I can use, which takes up the instance from creation part ie. <div ng-controller="MyController as myCtrl"> @rnrneverdies ,@glendaviesnz

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.