• About Morris Development
  • A Focus for Cloud Efficiency
    • Microsoft Azure
    • Amazon Web Services
  • What our Clients Say
  • Our Products
    • PreschoolDB
    • WebinarDB
  • Contact Us

Morris Development

Custom System Development and Integration

July 18, 2016

Angular Components Replace Controllers. Examples in TypeScript!

The next step to preparing yourself for Angular 2.0 is to move from the Controller model to Component model.  If you’ve had any experience with directives, you’ll see the format of what we’d use for a controller in TypeScript is similar.

(I stripped out our main code, leaving what we use as a framework.)

  
module Application.Controllers.Contact {
    class contactList {

        static $inject = ['$location', '$window', '$cookies', '$log', '$http', 'contactFact'];

        constructor(           
        private $location: ng.ILocationService,
        private $window: ng.IWindowService,
        private $cookies: Types.ICookiesService,
        private $log: ng.ILogService,
        private $http: ng.IHttpService,
        private contactFact: Application.Services.Contact.contactFact
        ) {

        }

    }
    app.component("contacts", {
        templateUrl: "partials/contact-list.html",
        bindings: { /* values we want to access from outside the component */},
        controller: contactList,
        controllerAs: "vm"
    });
}

So, we’ve taken the template and controller function away from the ngRoute and put it in the components. We’ve also added “bindings”, which are just like directives, where you can add one-way or two-way variables. In this case, variables that you name as “public” in the controller function will be used.

The route is changed a bit. There are several ways to change it, but I’ve just settled on an extremely easy method for now:

basically, I just ditch everything and change the template to what would be a directive!

app.config(['$routeProvider', '$locationProvider',
  function ($routeProvider, $locationProvider) {
      //  console.log($routeProvider);
      $routeProvider
        .when('/', {
            template: ""
        })
          .  

  }]);

There is a LOT more detailed information here: https://app.pluralsight.com/library/courses/building-components-angular-1-5/table-of-contents

Article by MacGyver / AngularJS, TypeScript / angular, components, typescript

About MacGyver

I've worked with database systems for over 20 years, and started my own company in 2000. Almost all my business consists of internal database systems, either ERP or CRM. My programming is primarily in Angular / Microsoft C# and MS SQL.

About This Site

Morris Development has been specializing in internal database system design and integration since 1999. We provide long-term management and support of secure data systems for many businesses as well as developing the more complex code structures for ERP systems like Intellievent, Apidas, and AVMS.

This site is primarily for our developers to keep track up various technologies and updates that are used by Morris Development.

Training

Integrating Angular Microsite with .Net

Private Data Caching with Google Storage

Continuous Deployment for Production Releases?

Azure Websites – the perfect Angular host

Angular 2

  • Angular 2 Authentication
  • Angular Command Line Interface
  • Material Design for Angular
  • Using Observables in Angular 2

Mentors

  • Ben Nadel
  • Dan Wahlin
  • Deborah Kurata
  • John Papa

Staff

  • Dan Morris

Training

  • Google Development Courses
  • Microsoft Virtual Academy
  • PluralSight
  • Test Deep Links

© 2025 · Morris Development