Skip to main content

Posts

Featured

Angular Component with controller

In the last post we discussed how to create a simple component without a controller. In this post we will add controller to the component. Controller in component is pretty much similar to the controller in directive. Component with controller will look something like : var app = angular.module('app', [ ]); var moviesController=function(){ } app.component('movieList', { templateUrl:'movie-list.html', controller:moviesController }); We need to use "ControllerAs" syntax if we want to add data or functions on the controller as shown below var moviesController=function(){ var vm=this; vm.movies=[ {title:'Star wars',rating:8,genre:'Action'}, {title:'Shawshank Redemption',rating:9.3,genre:'Drama'}, {title:'God Father I',rating:9.2,genre:'Crime'}, {title:'God Father II',rating:9.1,genre:'Crime'}, ]; }; app.component('movieList', {     ...

Latest posts

Introduction to components in Angular 1.5

ng-pluralize directive

Call multiple functions in ng-click

Sort data from the controller in angularjs

ng-strict-di in angularjs

ng-switch directive in angular

Angularjs Foreach loop

Allowing global functions as controllers in angularjs

Creating a custom filter in angularjs

Multi watch with $watchGroup in angular