Skip to main content

Injecting one controller into another controller in AngularJs

We can use functionality of one controller into another controller

Here for injecting one controller into another one we have to use $controller service

it will instantiate a controller inside another controller


Syntax:

app.controller('Cntrl1',  function () {
    this.MethodTest = function () {
      // functionality
    }
});

app.controller('Cntrl2', ['$scope', '$controller', function ($scope, $controller) {
     var testCtrl= $controller('Cntrl1');
     testCtrll.MethodTest();
}]);

Comments

Contact Form

Name

Email *

Message *

Popular posts from this blog

Exporting DataTable to Excel in C# Using Interop

Introduction I would like to share a utility that can be used to export a datatable to Excel file using C#. We have various approaches to perform this activity. In ASP.NET we can do this by changing the Content type to xls but in C# .Net we might have various other approaches. Through this article we will learn how to export a data table to Excel using Interop. Code and Steps Here in this application we will use a Sample datatable and then learn how to export data to an Excel file. We will learn the following things in this article: Creating Excel file using C# Writing data to cells Formatting data to cells Working with Excel range 1. Adding References First we need to add a reference for Microsoft.office.interop.Excel as in the following: 2. Adding sample data table to the code Use the following code to add the sample data table:     static   DataTable  GetTable()     {       ...

Adding CheckBox Column in DataGridView in C# Window Forms

Introduction  I would like to share three ways to add a checkbox to a DataGridView in a C# Windows Forms application. We will learn the following three ways to add a checkbox to a DataGridView: Binding a List to a DataGridView having a bool property Binding a datatable to a DataGridView having a bool column Adding a checkbox column (DataGridViewCheckBoxColumn) to the DataGridView. Procedure 1. Binding a List to a DataGridView having a bool property. Add the following class to the project: public   class  Emp   {       public   bool  isMarried {  get ;  set ; }       public   string  Name {  get ;  set ; }       public   string  city {  get ;  set ; }      }   We have added isMarried as a Boolean property.   Creating a List of Emp c...

Indexes In SQL SERVER in Hindi Part 1