Linking one controller to another to call service on ng-click - angularjs

I have two templates with respective controllers and service files. One template's(fleetListTemplate) controller(fleetListController) loads data from its service file(fleetService) and displays in its view(fleetListTemplate).
When this happens, and I click on one of the loaded data from fleetService, I should link fleetListController to fleetSummaryController to get data from its service file (fleetSummaryService) and display in fleetSummaryTemplate view.
Can someone please help me with the coding? Thank you.
The following are the respective modules, templates, controllers and service files.
fleetListModule
"use strict";
angular.module("fleetListModule", []);
fleetListTemplate
<div class="panel1 panel-primary">
<div class="panel-heading" align="center">TRUCKS</div>
<table class="table table-bordered table-condensed table-striped">
<tr>
<th>TruckID</th>
<th>Status</th>
<th>Dest.</th>
<th>Alerts</th>
</tr>
<tr ng-repeat="truck in trucks" ng-click="summaryData()">
<td>{{truck.truckID}}</td>
<td>{{truck.status}}</td>
<td>{{truck.destination}}</td>
<td>{{truck.alerts}}</td>
</tr>
</table>
</div>
fleetListController
"use strict";
angular.module("fleetListModule").controller("fleetListController",
['$scope', 'fleetsService',
function ($scope, fleetsService) {
$scope.trucks = fleetsService.getTrucks();
$scope.summaryData = function () {
$rootScope.$broadcast('obtainSummary');
}
}]);
fleetSummaryModule
"use strict";
angular.module("fleetSummaryModule", []);
fleetSummaryTemplate
<div class="panel2 panel-primary">
<div class="panel-heading">Summary</div>
<table class="table table-bordered table-condensed table-striped">
<tr ng-repeat="summary in truckSummary">
<td>Truck ID: {{summary.truckID}}</td>
<td>Trailer ID: {{summary.trailerID}}</td>
<td>Driver ID: {{summary.driverID}}</td>
<td>Truck Number: {{summary.truckNumber}}</td>
<td>Trailer Number: {{summary.trailerNumber}}</td>
<td>Insurance Due Date: {{summary.insuranceDueDate}}</td>
<td>Maintenance Due Date: {{summary.maintenanceDueDate}}</td>
</tr>
</table>
</div>
fleetSummaryController
"use strict";
angular.module("fleetSummaryModule").controller("fleetSummaryController",
['$scope', 'fleetSummaryService',
function ($scope, fleetSummaryService) {
$scope.$on('obtainSummary', function (event, args) {
$scope.truckSummary = fleetSummaryService.getSummary();
})
}]);
fleetSummaryService
"use strict";
angular.module("fleetSummaryModule").service("fleetSummaryService",
function () {
this.getSummary = function () {
return summary;
};
this.getSummary = function (truckID) {
for (var i = 0, len = truckSummary.length; i < len; i++) {
if (truckSummary[i].truckID === parseInt(truckID)) {
return truckSummary[i];
}
}
return {};
};
var truckSummary = [
{
truckID: 1,
trailerID: '123',
driverID: 'Alex123',
truckNumber: 'hyt 583',
trailerNumber: 'xyz213',
insuranceDueDate: '25-12-2015',
maintenanceDueDate: '31-12-2015'
},
{
truckID: 2,
trailerID: '456',
driverID: 'Alex123',
truckNumber: 'hyt 583',
trailerNumber: 'xyz213',
insuranceDueDate: '25-12-2015',
maintenanceDueDate: '31-12-2015'
},
{
truckID: 3,
trailerID: '789',
driverID: 'Alex123',
truckNumber: 'hyt 583',
trailerNumber: 'xyz213',
insuranceDueDate: '25-12-2015',
maintenanceDueDate: '31-12-2015'
}
];
});

This simple example show to you how to share data between 2 controllers "in one app"
using common service.
angular.module("app", []);
///controller1
angular.module("app").controller("controller1", function ($scope, service) {
$scope.lists = [
{ name: "maher" },
{ name: "Gaurav Ram" },
{ name: "Shaun Scovil" }
];
$scope.send = function () {
service.set("lists", $scope.lists); //set(key, value)
$scope.lists = []; //optional
}
});
///controller2
angular.module("app").controller("controller2", function ($scope, service) {
$scope.lists = [];
//get data from broadcast on the root
service.get("lists"); // get(key)
//set data
$scope.resive = function () {
if (angular.isUndefined($scope.broadcast)) {
$scope.alert = "No data to resive!";
} else {
$scope.alert = null;
$scope.lists = $scope.broadcast;
}
}
});
///service
angular.module("app").service("service", function ($rootScope) {
this.set = function (key, value) {
$rootScope.$broadcast(key, value);
}
this.get = function (key) {
$rootScope.$on(key, function (event, data) {
$rootScope.broadcast = data;
});
}
});
<!doctype html>
<html ng-app="app">
<head>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<div ng-controller="controller1" class="col-md-6 col-sm-6 col-xs-6">
<div class="page-header">
<h1>controller 1</h1>
</div>
<button ng-click="send()" class="btn btn-primary">Send</button>
<div class="clearfix"></div>
<br/>
<div class="alert alert-info" ng-if="lists.length == 0">Data <b>sent</b> to controller 2, click Resive button to get data</div>
<ul class="list-group">
<li ng-repeat="list in lists" class="list-group-item" ng-bind="list.name"></li>
</ul>
</div>
<div ng-controller="controller2" class="col-md-6 col-sm-6 col-xs-6">
<div class="page-header">
<h1>controller 2</h1>
</div>
<button ng-click="resive()" class="btn btn-success">Resive</button>
<div class="clearfix"></div>
<br />
<div class="alert alert-info" ng-bind="alert" ng-if="alert"></div>
<ul class="list-group">
<li ng-repeat="list in lists" class="list-group-item" ng-bind="list.name"></li>
</ul>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular.min.js"></script>
</body>
</html>

Related

Populate a combobox in Angular with Java BackEnd

The thing is as told in the title.
(function(){
var app = angular.module('sbi', [ ]);
app.controller('PanelController', function (){
this.tab = 1;
this.selectTab = function (setTab){
this.tab = setTab;
};
this.isSelected = function(checkTab) {
return this.tab === checkTab;
};
});
app.controller('MyCtrl', function($scope, $compile) {
'use strict';
$scope.data = { "name": ""};
$scope.reset = function() {
$scope.data.name = "";
$scope.data.codeSub = "";
$scope.data.cognSub = "";
$scope.data.codfis = "";
$scope.data.drpdownvalue = "";
$scope.form.$setPristine();
}
});
app.controller('DdController', function($scope, $compile) {
'use strict';
var loadUrl = contextName+"/subinstaller/inserimento/dettaglio.do?methodName=doListenerStato";
$.ajax({
async: false,
url : loadUrl,
type: "GET",
data: data,
dataType: 'json',
cache: false,
complete: function(){
_show_(false,'waitPanel');
},
success : function (data, stato) {
$('#service').empty()
for(var i = 0; i < data.length; i++) {
$("#service").append($('<option value="'+data[i].code+'">'+data[i].descr+'</option>'));
}
$('#service').trigger("chosen:updated");
},
error : function (richiesta, stato, errori) {
_show_(false,'waitPanel');
alert("error caricaServices");
}
});
});
})();
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.min.js"></script><!DOCTYPE html>
<html ng-app="sbi">
<head>
<link href="utils/bootstrap.min.css" rel="stylesheet" type="text/css"/>
<style>
table, td { border-width: 2px; border-collapse: collapse; padding: 15px; color: #000000; text-align: center; }
table.pos_fixed1 { position:relative; top:30px; left:10px; }
</style>
</head>
<body>
<form name="form">
<div data-ng-controller="MyCtrl">
<table summary="" width="10%" class="pos_fixed1" align="center">
<tr><td>Code Subinstaller<br><input type="text" ng-model="data.codeSub" /></td>
<td>Stato<br>
<select ng-model="data.drpdownvalue">
<option value=""> -- Seleziona -- </option>
</select> </td><td></td></tr>
<tr><td>Nome Sub Installer<input type="text" ng-model="data.name" /></td>
<td>Cognome Sub Installer<input type="text" ng-model="data.cognSub" /></td>
<td>Codice Fiscale<input type="text" ng-model="data.codfis" /></td></tr>
</table><br><br>
</form>
<section>
<div class="text-center">
<form name="form" id="form" novalidate>
<div>
<button class="btn-xs" data-ng-click="">Cerca</button>
<button class="btn-xs" ng-click="reset()">Pulisci</button>
</div>
</div>
</form>
</div>
</section>
<section ng-controller="PanelController as panel">
<ul class="nav nav-pills" >
<li ng-class="{ active:panel.isSelected(1) }"> <a href ng-click="panel.selectTab(1)">Risultati</a></li>
<li ng-class="{ active:panel.isSelected(2) }"> <a href ng-click="panel.selectTab(2)">Dettaglio</a></li>
</ul>
<div class="panel" ng-show="panel.isSelected(1)">
<h4>Risultati</h4>
<p> :))) </p>
</div>
<div class="panel" ng-show="panel.isSelected(2)">
<h4>Dettaglio</h4>
<p> Not skilled enough yet</p>
</div>
</section>
<script type="text/javascript" src="utils/angular.min.js"></script>
<script type="text/javascript" src="controllers/sbi_inserimento_controller1.js"></script>
</body>
</html>
The function "DoListenerStato" has its query and it works (tried in Java)
But the combobox is not being populated.
Have I used ajax correctly? If so, what can I do?
I'd prefer to keep using ajax for this work, if possible.
Can you try $http.get instead of $.ajax.
in Controller.js file:
$scope.data = {};
$http.get(loadUrl).then(function (response){
$scope.data = response.data;
//success callback
}, function (response) {
//error callback
});
Since you already have data.**** in your ng-model this should solve it.

calling function within td element to set the text

I am trying to call a function within a <td> element that is part of a ng-repeat. Any ideas how to get this to work? I have tried so many things and no joy. The issue is the cartperf.perf_desc binding.
<table class="table table-striped table-condensed" >
<tr ng-repeat="cartperf in $ctrl.cartSummary">
<td class="cs-cart-sum-td">{{cartperf.id}}</td>
<td class="cs-cart-sum-td" ng-bind="$ctrl.myNewHtml(cartperf.perf_desc)"></td>
<td class="cs-cart-sum-td">{{cartperf.perf_dt}}</td>
<td class="cs-cart-sum-td">{{cartperf.theater}}</td>
<td class="cs-cart-sum-td">{{cartperf.num_tkts}}</td>
<td class="cs-cart-sum-td">{{cartperf.due_amt}}</td>
<td class="cs-cart-sum-td">
<button type="button" data-perf='cartperf' class="btn btn-link cs-btn-delete" ng-click="$ctrl.confirmDelete(cartperf)">{{cartperf.RemoveBtnTxt}}</button>
</td>
</tr>
</table>
Controller that drive the template
function cartSummaryController() {
this.$onInit = function () {
//Get content from Parent
this.globalContent = this.getGlobalContent;
this.cartSummary = this.cartPerfs;
this.myHtml = this.myNewHtml;
}; //End $onInit
}
Main Controller
function subAppController($sce) {
this.$onInit = function () {
//Get content from Parent
this.globalContent = this.getGlobalContent;
}; //End $onInit
this.continueClick = function () {
console.log("Continue Selected");
};
this.currentStep = 1;
this.contentJson = pcContent;
this.globalContentJson = pcGlobalContent;
this.cartPerfs = pcCartPerfs
//Called from the template to get global content.
this.getGlobalContent = function (module, item) {
var globalContent = new contentProvider(this.globalContentJson);
var result = globalContent.get(module, item);
return result;
}
this.myNewHtml = function (item) {
var result = $sce.trustAsHtml(item);
return result;
}
//Get the current count of valid performance in the cart
// We use this to determine if we hide/disable the continue buttons.
this.min_perfs = this.contentJson.required_min_perfs;
this.curr_perf_count = this.cartPerfs.length;
this.continueActive = this.curr_perf_count >= this.min_perfs;
}
Main Template
<div class="container-fluid">
<!--Top (Bread crumbs and Cart Summary)-->
<div class="cs-app-top row">
<div class="cs-app-left col-sm-3">
<div class="pull-left">
<div class="bcrumbs">Step 1 > Step2</div>
<div>
<label class="cs-page-title">{{$ctrl.contentJson.page_title}}</label>
</div>
</div>
</div>
<div class="cs-app-right pull-right col-sm-9">
<cart-summary content-json="$ctrl.contentJson"
get-global-content="$ctrl.getGlobalContent(module,item)"
cart-perfs="$ctrl.cartPerfs"
my-new-html="$ctrl.myNewHtml(item)">
</cart-summary>
<div class="cs-continue-btn-div pull-right">
<button class="cs-continue-btn cs-btn"
ng-bind="$ctrl.globalContent('subpackage','continueBtnText')"
ng-class="{'hidden': !$ctrl.continueActive}"
ng-disabled="!$ctrl.continueActive"
ng-click="$ctrl.continueClick()" ></button>
</div>
</div>
</div>
<!--Header Content-->
<div class="cs-header row">
<div ng-bind-html="$ctrl.myNewHtml($ctrl.contentJson.page_header)"></div>
</div>
<!--Main Section (perf-list)-->
<div class="cs-app-main row">
<div>
<perf-list ng-if="$ctrl.currentStep == 1"
content-json="$ctrl.contentJson"
get-global-content="$ctrl.getGlobalContent(module,item)">
</perf-list>
</div>
</div>
<!--Footer-->
<div class="cs-app-footer row">
<div class="cs-continue-btn-div pull-right">
<button class="cs-continue-btn cs-btn"
ng-bind="$ctrl.globalContent('subpackage','continueBtnText')"
ng-disabled="!$ctrl.continueActive"
ng-click="$ctrl.continueClick()"></button>
</div>
</div>
</div>
--Module
var myApp = angular.module('subPackages', ['ngMaterial', 'ngMessages','ngSanitize']).config(function($sceDelegateProvider) {
$sceDelegateProvider.resourceUrlWhitelist([
// Allow same origin resource loads.
'self',
// Allow loading from our assets domain. Notice the difference between * and **.
'Protected content**'
]);
});
(function (app) {
'use strict';
app.component('appComponent', {
templateUrl: '../subpackages/templates/app-template.html',
controller: subAppController
});
app.component('cartSummary', {
templateUrl: '../subpackages/templates/cart-summary.template.html',
controller: cartSummaryController,
bindings: {
contentJson: '<',
cartPerfs: '<',
getGlobalContent: '&',
myNewHtml: '&'
},
});
app.component('perfList', {
templateUrl: '../subpackages/templates/perf-list.templateV3.html',
controller: PerfListController,
bindings: {
contentJson: '<',
getGlobalContent: '&'
},
});
})(myApp);
You could create a custom directive as show in Execute a function inside ng-repeat in AngularJS
Found the solution. Instead of doing this
<td class="cs-cart-sum-td" ng-bind="$ctrl.myNewHtml(cartperf.perf_desc)"></td>
I did this.
<td class="cs-cart-sum-td" ng-bind-html="$ctrl.myHtml({item: cartperf.perf_desc})"></td>

Error: [ng:areq] Argument 'ModalController' is not a function, got undefined

I used to have all my code in one big js file, but i separated everything -- including controllers to make it modular as my little app grows (and for learning porpoises). So my ui-bootstrap modal code is in this controller and is called and worked fine. When i split the controllers into separate files i get the error below. How do i fix?
app.js
var personApp = angular.module('PersonApp', ['ngAnimate', 'ngSanitize', 'ui.bootstrap']);
personController.js
personApp.controller('PersonController', function ($scope, $uibModal, PersonService) {
$scope.addPerson = function () {
$scope.modalModel = {
Id: 0,
firstName: '',
lastName: '',
birthDate: ''
};
$scope.$uibModalInstance = $uibModal.open({
templateUrl: '/Modal/AddEditPersonModal',
controller: 'ModalController',
scope: $scope
})
}
personModalController.js
personApp.controller('ModalController', ['$scope', function ($scope, $uibModalInstance) {
$scope.close = function () {
$scope.$uibModalInstance.close();
var modalId = $scope.modalModel.Id;
for (var i = 0; i < $scope.persons.length; i++) {
var person = $scope.persons[i];
if (person.Id === $scope.oldValues.Id) {
$scope.persons[i].firstName = $scope.oldValues.firstName;
$scope.persons[i].lastName = $scope.oldValues.lastName;
$scope.persons[i].birthDate = $scope.oldValues.birthDate;
break;
}
};
};
$scope.save = function () {
$scope.$uibModalInstance.dismiss('cancel');
};
}]);
Index.cshtml
#{
ViewBag.Title = "Home Page";
}
<link href="~/Content/PageSpecific/Index.css" rel="stylesheet" />
<script src="~/Scripts/PersonApp/app.js"></script>
<script src="~/Scripts/PersonApp/filters/personFilter.js"></script>
<script src="~/Scripts/PersonApp/services/personService.js"></script>
<script src="~/Scripts/PersonApp/controllers/personController.js"></script>
<script src="~/Scripts/PersonApp/controllers/personModalController.js"></script>
<script src="~/Scripts/PageSpecific/Index.js"></script>
<div ng-app="PersonApp" class="container">
<div ng-controller="PersonController">
<div class="mb20 mt15">
<input type="text" placeholder="Search Person" ng-model="searchPerson" />
<button type="button" class="btn btn-primary pull-right mb15 mr20" data-toggle="modal" ng-model="addPersonModel" ng-click="addPerson()">Add New</button>
</div>
<table class="table header-fixed">
<thead>
<tr>
<th ng-click="sortData('Id')">
ID <div ng-class="getSortClass('Id')"></div>
</th>
<th ng-click="sortData('firstName')">
First Name <div ng-class="getSortClass('firstName')"></div>
</th>
<th ng-click="sortData('lastName')">
Last Name <div ng-class="getSortClass('lastName')"></div>
</th>
<th ng-click="sortData('birthDate')">
BirthDate <div ng-class="getSortClass('birthDate')"></div>
</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="person in filteredPersons | orderBy: sortColumn:reverseSort | filter : searchPerson">
<td>{{person.Id}}</td>
<td>{{person.firstName}}</td>
<td>{{person.lastName}}</td>
<td>{{person.birthDate | date:"MM/dd/yyyy"}}</td>
<td>
<span class="fa fa-pencil-square-o"></span>
<span class="fa fa-remove"></span>
</td>
</tr>
</tbody>
</table>
<ul uib-pagination total-items="persons.length" ng-model="currentPage" max-size="maxSize" class="pagination-sm" boundary-links="true" rotate="false" items-per-page="numPerPage" num-pages="numPages"></ul>
<pre>Page: {{currentPage}} / {{numPages}}</pre>
</div>
</div>
<style>
</style>
Was a simple mistake on my part. Changed the order of referenced files in the index.cshtml. personController had function trying to call modalcontroller (in personmodalcontroller)
This:
<script src="~/Scripts/PersonApp/controllers/personController.js"></script>
<script src="~/Scripts/PersonApp/controllers/personModalController.js"></script>
Became this:
<script src="~/Scripts/PersonApp/controllers/personModalController.js"></script>
<script src="~/Scripts/PersonApp/controllers/personController.js"></script>
You missed to include,$uibModalInstance
personApp.controller('ModalController', ['$scope' function ($scope, $uibModalInstance) {
$scope.close = function () {
$scope.$uibModalInstance.close();
var modalId = $scope.modalModel.Id;
for (var i = 0; i < $scope.persons.length; i++) {
var person = $scope.persons[i];
if (person.Id === $scope.oldValues.Id) {
$scope.persons[i].firstName = $scope.oldValues.firstName;
$scope.persons[i].lastName = $scope.oldValues.lastName;
$scope.persons[i].birthDate = $scope.oldValues.birthDate;
break;
}
};
};
$scope.save = function () {
$scope.$uibModalInstance.dismiss('cancel');
};
}]);
Re define the ModalController like this. You have not injected the $uibModalInstance dependency in your controller. the $uibModalInstance inside the function parameters are only the alias reference to your dependency. You have to inject the dependency first before aliasing the dependency.
personApp.controller('ModalController', ['$scope', '$uibModalInstance', function ($scope, $uibModalInstance) {
$scope.close = function () {
$scope.$uibModalInstance.close();
var modalId = $scope.modalModel.Id;
for (var i = 0; i < $scope.persons.length; i++) {
var person = $scope.persons[i];
if (person.Id === $scope.oldValues.Id) {
$scope.persons[i].firstName = $scope.oldValues.firstName;
$scope.persons[i].lastName = $scope.oldValues.lastName;
$scope.persons[i].birthDate = $scope.oldValues.birthDate;
break;
}
};
};
$scope.save = function () {
$scope.$uibModalInstance.dismiss('cancel');
};
}]);

How to pass data to other scopes variables in angularjs?

I have controller
<div ng-controller="LeftSideNavWorkController as vm" ">
<div ng-repeat="item in vm.items track by $index">
<div ng-click="vm.hideAllElements()>Hide</div>
<div ng-show = "showChildren[$index]" >Show/Hide element<div>
</div>
</div>
in controller:
vm.hideAllElements = hideAllElements;
vm.items = [... ... ...]; //some array of items
function hideAllElements() {
//how set all showChildren[] variables to false?
}
the task is that when I click on one it should set all vm.show = false
TRY THIS ONE:
HTML:
<div ng-controller="LeftSideNavWorkController as vm" ">
<div ng-repeat="item in vm.items track by $index">
<div ng-click="vm.hideAllElements()>Hide</div>
<div ng-show = "showChildren[$index]" >Show/Hide element<div>
</div>
</div>
CTRL:
(function() {
'use strict'
angular
.module('myApp')
.controller('appController', appController);
// main.js
function appController($scope, $interval) {
var vm = this;
vm.items = [1, 2, 3, 4, 5];
vm.hideAllElements = hideAllElements;
vm.show = true;
function hideAllElements() {
vm.items.forEach(function(obj, i) {
vm.show = false;
});
}
}
}());
You just have to do
In your view
<div ng-controller="LeftSideNavWorkController as vm" ">
<div ng-repeat="item in vm.items track by $index">
<div ng-click="vm.hideAllElements()>Hide</div>
<div ng-show = "item.show" >Show/Hide element<div>
</div>
</div>
In controller function:
function hideAllElements() {
vm.items.forEach(function(item) {
item.show = false;
}
}

Error "cannot set property gridDim of undefined" in angular js

Getting error "cannot set property gridDim of undefined" while using ng-grid in angular js. i have already declared vm.gridOptions = { data: 'vm.course_view'};.plz help me
<section class="mainbar">
<section class="matter">
<div class="container">
<div class="row" ng-controller="Course_view">
<div class="col-lg-5 col-lg-offset-2">
<div class="widget wblue">
<div vis-widget-header title="{{vm.title}}"></div>
<div class="widget-content user">
<!-- <table data-toggle="table" data-height="150" class="table table-condensed table-hover">
<thead>
<tr>
<th>Lesson</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="c in vm.course_view"
>
<td>{{c.firstName}}</td>
</tr>
</tbody>
</table> -->
<div class="gridStyle" ng-grid="course_view"></div>
</div>
<div class="widget-foot">
<div class="clearfix"></div>
</div>
</div>
</div>
</div>
</div>
</section>
Here is Code for controller
(function() {
'use strict';
angular
.module('app.course_view')
.controller('Course_view', Course_view);
/* #ngInject */
function Course_view($state, dataservice, logger) {
var vm = this;
vm.course_view = [];
vm.title = 'Course_view';
vm.gridOptions = { data: 'vm.course_view', columnDefs: [
{field:'firstName', displayName:'firstName'}
]};
activate();
function activate() {
return getCourse_View().then(function() {
logger.info('Activated course_view View');
});
}
function getCourse_View() {
return dataservice.getCourse_View().then(function(data) {
vm.course_view = data;
debugger;
return vm.course_view;
});
}
}
})();
Please, try to change the following code:
<div class="row" ng-controller="Course_view">
on
<div class="row" ng-controller="Course_view as courseCtrl">
and
<div class="gridStyle" ng-grid="course_view"></div>
on
<div class="gridStyle" ng-grid="courseCtrl.course_view"></div>
And please, give me feedback about your success/fail in comments.
UPDATE:
I've created JSFiddle for you with working example.
I'm a little bit simplified example, but it should work.
<div ng-controller="CourseViewCtrl as ctrl">
<div class="gridStyle" ng-grid="ctrl.gridOptions"></div>
</div>
(function() {
'use strict';
var myApp = angular.module('myApp',['ngGrid']);
myApp.controller('CourseViewCtrl', CourseViewCtrl);
function CourseViewCtrl($http) {
var vm = this;
vm.course_view = [];
vm.gridOptions = {
data: 'ctrl.course_view'
};
activate();
function activate() {
return $http.get("/data").success(function(data) {
vm.course_view = data;
});
};
}
})();
I want to note on main differences between your code:
Grid options in the controller:
vm.course_view = [];
vm.gridOptions = {
data: 'ctrl.course_view'
};
Grid on the view:
<div class="gridStyle" ng-grid="ctrl.gridOptions"></div>

Resources