Exchange Data Between Directive and Controller in AngularJS

  • The project required me to write a directive for a canvas, get the Base64 image data when a user draws on it, and make it available to the controller of the page which contains the directive.
  • This boils down to the fact that you need to access the scope of a Directive from a page Controller and access the scope of a page Controller from a Directive.
  • Now let’s say we have the following controller:

    And the following template:

    The problem: we would like to bind the count variable of myCtrl to the internalCount variable of the counter directive.

  • This can easily be solved by binding a variable from the controller to the scope of the directive.
  • Your directive should now look like this:

    And your template like this:

    You will find a working fiddle here with all the code to this quick tutorial on how to exchange data between a directive and controller in AngularJS.

In this Quick Tutorial we will look at How to Exchange Data Between Directive and Controller in AngularJS and bind the scopes to each other.
Continue reading “Exchange Data Between Directive and Controller in AngularJS”

Exchange Data Between Directive and Controller in AngularJS

  • The project required me to write a directive for a canvas, get the Base64 image data when a user draws on it, and make it available to the controller of the page which contains the directive.
  • This boils down to the fact that you need to access the scope of a Directive from a page Controller and access the scope of a page Controller from a Directive.
  • Now let’s say we have the following controller:

    And the following template:

    The problem: we would like to bind the count variable of myCtrl to the internalCount variable of the counter directive.

  • This can easily be solved by binding a variable from the controller to the scope of the directive.
  • Your directive should now look like this:

    And your template like this:

    You will find a working fiddle here with all the code to this quick tutorial on how to exchange data between a directive and controller in AngularJS.

In this Quick Tutorial we will look at How to Exchange Data Between Directive and Controller in AngularJS and bind the scopes to each other.
Continue reading “Exchange Data Between Directive and Controller in AngularJS”

Exchange Data Between Directive and Controller in AngularJS

  • The project required me to write a directive for a canvas, get the Base64 image data when a user draws on it, and make it available to the controller of the page which contains the directive.
  • This boils down to the fact that you need to access the scope of a Directive from a page Controller and access the scope of a page Controller from a Directive.
  • Now let’s say we have the following controller:

    And the following template:

    The problem: we would like to bind the count variable of myCtrl to the internalCount variable of the counter directive.

  • This can easily be solved by binding a variable from the controller to the scope of the directive.
  • Your directive should now look like this:

    And your template like this:

    You will find a working fiddle here with all the code to this quick tutorial on how to exchange data between a directive and controller in AngularJS.

In this Quick Tutorial we will look at How to Exchange Data Between Directive and Controller in AngularJS and bind the scopes to each other.
Continue reading “Exchange Data Between Directive and Controller in AngularJS”

AngularJS Fundamentals

AngularJS Fundamentals course by @simpulton #angularjs

  • In this series, you will learn how to build a non-trivial AngularJS application from the ground up through a series of small, digestible lessons.
  • As we build out our sample application, Eggly, you will quickly start to identify useful techniques that you can apply to your own projects.
  • In this first series, we are going to focus on the absolute essentials for getting an AngularJS application up and running.
  • We will start with a static HTML page and learn how to bootstrap an AngularJS application and add in functionality using AngularJS views and controllers.
  • When we complete this section, you will have a functioning Eggly application where you can create, update and delete bookmarks and filter them based on the selected bookmark category.

AngularJS is an incredibly powerful framework but sometimes it can be confusing and frustrating trying to figure out how all of these amazing features actually fit together. In this series, you will learn how to build a non-trivial AngularJS application from the ground up through a series of small, digestible lessons.

As we build out our sample application, Eggly, you will quickly start to identify useful techniques that you can apply to your own projects. The videos series is broken out into three series so that you can start at whatever level is most appropriate for you.

### Getting Started

In this first series, we are going to focus on the absolute essentials for getting an AngularJS application up and running. We will start with a static HTML page and learn how to bootstrap an AngularJS application and add in functionality using AngularJS views and controllers. When we complete this section, you will have a functioning Eggly application where you can create, update and delete bookmarks and filter them based on the selected bookmark category.

Don’t miss **[Part 2: Application Architecture](https://egghead.io/series/angularjs-application-architecture)**!

Continue reading “AngularJS Fundamentals”

Exchange Data Between Directive and Controller in AngularJS

  • The project required me to write a directive for a canvas, get the Base64 image data when a user draws on it, and make it available to the controller of the page which contains the directive.
  • This boils down to the fact that you need to access the scope of a Directive from a page Controller and access the scope of a page Controller from a Directive.
  • Now let’s say we have the following controller:

    And the following template:

    The problem: we would like to bind the count variable of myCtrl to the internalCount variable of the counter directive.

  • This can easily be solved by binding a variable from the controller to the scope of the directive.
  • Your directive should now look like this:

    And your template like this:

    You will find a working fiddle here with all the code to this quick tutorial on how to exchange data between a directive and controller in AngularJS.

In this Quick Tutorial we will look at How to Exchange Data Between Directive and Controller in AngularJS and bind the scopes to each other.
Continue reading “Exchange Data Between Directive and Controller in AngularJS”

AngularJS Fundamentals

AngularJS Fundamentals course by @simpulton #angularjs

AngularJS is an incredibly powerful framework but sometimes it can be confusing and frustrating trying to figure out how all of these amazing features actually fit together. In this series, you will learn how to build a non-trivial AngularJS application from the ground up through a series of small, digestible lessons.

As we build out our sample application, Eggly, you will quickly start to identify useful techniques that you can apply to your own projects. The videos series is broken out into three series so that you can start at whatever level is most appropriate for you.

### Getting Started

In this first series, we are going to focus on the absolute essentials for getting an AngularJS application up and running. We will start with a static HTML page and learn how to bootstrap an AngularJS application and add in functionality using AngularJS views and controllers. When we complete this section, you will have a functioning Eggly application where you can create, update and delete bookmarks and filter them based on the selected bookmark category.

Don’t miss **[Part 2: Application Architecture](https://egghead.io/series/angularjs-application-architecture)**!

Continue reading “AngularJS Fundamentals”

Exchange Data Between Directive and Controller in AngularJS

  • So in order to do this we need to emulate the ng-model behavior of an input in our Directive.
  • We can also remove the initialization of the internalCount variable in the directive.
  • To do this we will pass the variable as an attribute to the directive and use it to initialize the scope of the directive
  • This boils down to the fact that you need to access the scope of a Directive from a page Controller and access the scope of a page Controller from a Directive.
  • The project required me to write a directive for a canvas, get the Base64 image data when a user draws on it, and make it available to the controller of the page which contains the directive.

In this Quick Tutorial we will look at How to Exchange Data Between Directive and Controller in AngularJS and bind the scopes to each other.
Continue reading “Exchange Data Between Directive and Controller in AngularJS”