I've simplified this to its barebones - pulled out any properties that might be interfering (I can put em back in if you like) - even pointing it at local .json - and still getting no data in my grid.
I did see data in the sample that I dropped in, when it was pointing at the Northwind api, so I know I've got my i's crossed and t's dotted.
<div id="grid"></div>
This is in my controller:
$("#grid").kendoGrid({
dataSource: {
type: "odata",
transport: {
read: 'Content/data/Listings.json'
}
},
height: 550,
columns: [{
field: "Id",
title: "Id",
width: 240
},{
field: "State",
title: "State",
width: 240
}]
});
The call it makes is this (I have no control over this):
http://localhost/Wizmo-web/Content/data/Listings.json?$callback=jQuery112103831734413679999_1470962161424&"%"24inlinecount=allpages&"%"24format=json
It is returning data from my Listings.json (which I've ensured is valid):
[
{
"Id":557,
"State":"active",
"Title":"Matching Father Son Shirts I Am Your Father Shirt ",
},
{
"Id":558,
"State":"active",
"Title":"Baseball Hoodies Im All About That Base Hooded Swe",
}
]
But my grid is empty.
No errors, no nothing.
Stumped.
I looks like in your controller, you are trying to use the jQuery implementation of Kendo, instead of the supported Angular directives.
The Kendo UI grid features inherent integration with AngularJS using directives which are officially supported as part of the product. To make use of this integration, you need to reference the Angular scripts in your app and register the module incorporating the Kendo UI directives in the following way:
angular.module("myApp", [ "kendo.directives" ])
So in your controller, instead of using jQuery $("#grid").kendoGrid(...) to find the element and add your config object, you are actually going to use a config object on your controller scope:
$scope.mainGridOptions = {
//all your config options here
};
Then in your view, instead of using just <div id="grid"></div> you're actually going to use the Kendo directive here, and pass it the config object from your controller:
<kendo-grid options="mainGridOptions">
...
Kendo has some pretty good documentation on Angular implementation here
The actual problem is different - the dataSource configuration includes a type: "odata" setting, which does not correspond to the server response, so it should be removed. With this setting, the Kendo UI DataSource instance is not able to find the data items in the returned JSON, that's why no table rows are rendered.
http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-type
Here is a runnable example without the type setting:
http://dojo.telerik.com/ESija
The moment I add [ 'kendo.directives' ] to the module, everything dies. No errors, nothing.
Controller:
(function() {
'use strict';
angular
.module('WizmoApp', [ 'kendo.directives' ])
.controller('listingsController', listingsController);
listingsController.$inject = ['$http', '$location', '$stateParams', '$filter', 'toastr', 'DTOptionsBuilder', 'DTColumnDefBuilder', 'listingsService', 'datatableService', 'ngAuthSettings'];
function listingsController($http, $location, $stateParams, $filter, toastr, DTOptionsBuilder, DTColumnDefBuilder, listingsService, datatableService, ngAuthSettings) {
...
index.html:
<script src="Content/vendor/Metronic/global/plugins/jquery.min.js" type="text/javascript"></script>
...
<script src="Content/vendor/Metronic/global/plugins/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<script src="Content/vendor/datatables/media/js/jquery.dataTables.min.js" type="text/javascript"></script>
<script src="Content/vendor/angular/angular.min.js" type="text/javascript"></script>
<script src="Content/vendor/KendoUI/js/kendo.all.min.js"></script>
Related
When I run angular-d3plus independently (please note angular-d3plus also uses 'use strict' directive in js), it works well. But when I tried to make it part of my existing angularJS application (generated through JHipster) I see strictdi error in developer console of chrome as soon as it attempts to draw view where angular-d3plus directive is used;
angular.js:13920 Error: [$injector:strictdi] controller is not using explicit annotation and cannot be invoked in strict mode
I followed below simple steps for this integration (after bower install and adding d3 related js files in my index.html)
I added 'angular-d3plus' module in my app
angular
.module('myapp', [
...,
'angular-d3plus',
...
])
.run(run);
My controller code is;
(function() {
'use strict';
angular
.module('myapp')
.controller('myappController', myappController);
myappController.$inject = ['$translate', '$timeout'];
function myappController ($translate, $timeout) {
var vm = this;
vm.charttype="box";
vm.base_data = [
{"year": 1991, "name":"alpha", "value": 15, "group": "black"},
{"year": 1991, "name":"beta", "value": -10, "group": "black"},
{"year": 1991, "name":"gamma", "value": 5, "group": "black"}
];
}
})();
my angular-d3plus directive in my view is (for above controller);
<d3plus-box data="vm.base_data" id='name' y="value" x="year" ng-show="vm.charttype=='box'" ></d3plus-box>
</div>
when I take out above line of code, everything else works perfectly fine. I have tried this post to take out controller code from directive (editing angular-d3plus js) but of no use. I also attempted and observed no error when changed angularjs version of angular-d3plus demo to 1.5.8 (same as my application). Any help would be really appreciated!
EDIT1: edited directive in view as per #mariomol suggestion.
The thing is, if you use Controller As Name, you have to:
When making html tag use vm.base_data and vm.charttype
If you import Controller in html do ng-controller="Controller as vm"
Here a working example:
http://codepen.io/mariomol/pen/NbpKXP?editors=1111
best
To solve this, I had to take out controller function from directive
d3plusBox.$inject = ["angularD3plusUtils"];
function d3plusBox(angularD3plusUtils) {
console.log('d3plusBox entered');
return {
restrict: 'AE',
scope: angularD3plusUtils.scope({
data: '=',
id: '#',
x: '#',
y: '#',
size: '#?'
}),
template: angularD3plusUtils.template,
link: angularD3plusUtils.link,
controller: d3PlusBoxContr
};
}
d3PlusBoxContr.$inject = ["angularD3plusUtils", "$scope", "$element"]
function d3PlusBoxContr(angularD3plusUtils, $scope, $element) {
angularD3plusUtils.controller($scope, $element, 'box');
}
I am working on an Angular(1.5.8) project and use bower installed highcharts-ng github link
Added highcharts-ng as:
angular.module('myapp',
['highcharts-ng',
// more modules here..
])
In my html file, i use below:
<div class="row">
<highchart id="chart1" config="chartConfig"></highchart>
</div>
In my controller file:
DashboardController.$inject = ['$scope', 'Principal', 'LoginService', '$state'];
function DashboardController ($scope, Principal, LoginService, $state) {
$scope.chartConfig ={
....// configuration details
};
}();
I put the
<script src="bower_components/highcharts-ng/dist/highcharts-ng.js"></script>
into index.html
Unfortunately, I got such error:
angular.js:13920 TypeError: Cannot read property 'Chart' of undefined
at initChart (highcharts-ng.js:334)
at linkWithHighcharts (highcharts-ng.js:349)
at highchartsCb (highcharts-ng.js:463)
at processQueue (angular.js:16383)
at angular.js:16399
at Scope.$eval (angular.js:17682)
at Scope.$digest (angular.js:17495)
at Scope.$apply (angular.js:17790)
at done (angular.js:11831)
at completeRequest (angular.js:12033)
Can anyone shed some light on this please?
Details of chartConfig, it is a copy from https://github.com/pablojim/highcharts-ng which I use it for testing highcharts works or not :
function DashboardController ($scope) {
//This is not a highcharts object. It just looks a little like one!
$scope.chartConfig = {
options: {
//This is the Main Highcharts chart config. Any Highchart options are valid here.
//will be overriden by values specified below.
chart: {
type: 'bar'
},
tooltip: {
style: {
padding: 10,
fontWeight: 'bold'
}
}
},
//The below properties are watched separately for changes.
//Series object (optional) - a list of series using normal Highcharts series options.
series: [{
data: [10, 15, 12, 8, 7]
}],
//Title configuration (optional)
title: {
text: 'Hello'
},
//Boolean to control showing loading status on chart (optional)
//Could be a string if you want to show specific loading text.
loading: false,
//Configuration for the xAxis (optional). Currently only one x axis can be dynamically controlled.
//properties currentMin and currentMax provided 2-way binding to the chart's maximum and minimum
xAxis: {
currentMin: 0,
currentMax: 20,
title: {text: 'values'}
},
//Whether to use Highstocks instead of Highcharts (optional). Defaults to false.
useHighStocks: false,
//size (optional) if left out the chart will default to size of the div or something sensible.
size: {
width: 400,
height: 300
},
//function (optional)
// func: function (chart) {
// //setup some logic for the chart
// }
};
}
Include,
<script src="http://code.highcharts.com/stock/highstock.src.js"></script>
or
<script src="http://code.highcharts.com/highcharts.src.js"></script>
as explained in the git page.
Mahesh's answer is correct and solved my problem. Due to I am using Jhipster, import the script manually is not the best choice for me. Here's how to import it in JHipster project:
bower install highcharts --save
bower install highcharts --save
gulp inject:dev
it would inject the JS file into index.html automatically. In my case, the highcharts.js and highcharts-ng.js files were injected before angular.js which generated another error Uncaught ReferenceError: angular is not defined, it would be solved when move the highcharts related js injection after angular.js is injected.
For example:
<script src="bower_components/angular/angular.js"></script>
...
...
<script src="bower_components/highcharts/highcharts.js"></script>
<script src="bower_components/highcharts-ng/dist/highcharts-ng.js"></script>
I was able to successfully implement the API on web, here is what it looks like, I have a button in a regular html file...
<div>
<span class="radio-button radio-left" id="sandboxLinkButton">Sandbox Mode</span>
</div>
I include the script tag...
<script src="https://cdn.plaid.com/link/stable/link-initialize.js"></script>
and I include the following javascript in the html body...
<script type="text/javascript">
var sandboxHandler = Plaid.create({
clientName: 'SUM',
env: 'tartan',
product: 'auth',
key: 'test_key',
onSuccess: function(token) {
//window.location = '/accounts.html?public_token=' + token;
console.log("yes");
},
});
// Open the "Institution Select" view using the sandbox Link handler.
document.getElementById('sandboxLinkButton').onclick = function() {
sandboxHandler.open();
};
</script>
Now I want to do the same using angular js. I'm using an ionic framework (not that it really matters). So I first display the necessary html using the following...
app.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/app');
$stateProvider
.state('app', {
url: '/app',
templateUrl: 'templates/menu.html',
controller: 'AppCtrl'
})
});
My menu.html file contains the following button...
<span ng-click="create()" class="radio-button radio-left" id="sandboxLinkButton">Sandbox Mode</span>
on ng-click it reaches the following controller. I tried to implement the API in this controller to no avail...
app.controller('AppCtrl', function($scope, $ionicModal, $timeout) {
var sandboxHandler = Plaid.create({
clientName: 'SUM',
env: 'tartan',
product: 'auth',
key: 'test_key',
onSuccess: function(token) {
console.log("yes");
},
});
$scope.create = function() {
sandboxHandler.open();
}
});
I get the error Plaid is not defined in the controller. Why is that?
EDIT
I replicated a web app version using angular and it worked. I used the following CDN instead of the ionic/angular one
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
But I still can't get it to work on my ionic web app. Has anyone else ever come across this issue?
When I included the library I immediately got the following error in the browser: Uncaught TypeError: Cannot read property 'appendChild' of null
There are similar questions about this error regarding different libraries here and here, however I was not able to solve the problem based on those answers.
The closest thing to a solution that I found was in this issue report within the Plaid repository on GitHub. It describes a problem with the library not working when placed in the <head> tag. A commit within this issue report describes that this problem can be solved by including the script inside the <body> tag instead of the <head> tag.
I would recommend subscribing to the issue report to see whether other solutions will be introduced in the future.
So tldr; Try moving the <script> tag from <head> to the <body>.
You can simply use the Plain angular wrapper that I created:
https://github.com/khashayar/ng-plaid
I am experiencing some issues with implementing the angular-google-maps plugin (https://angular-ui.github.io/angular-google-maps/#!/) for the Ionic Framework software in that I cannot get the map to render at all. Crazy thing is that the GoogleMapAPI promise is being triggered (as per alerts that I am placing within there for testing purposes) but no map is rendered to the screen.
My index.html file (in my iOS directory) uses the following file calls:
_assets/_js/_plugins/lodash-2.4.1.min.js"
lib/ionic/js/ionic.bundle.js"
lib/ngCordova/ng-cordova.min.js"
cordova.js"
_assets/_js/_plugins/angular-google-maps-2.0.7.min.js"
_assets/_js/app.js"
_assets/_js/_custom/factories.js"
_assets/_js/_custom/controllers.js"
I have double checked that these files are all present in the locations I have listed in the script src attributes so no problems there.
The Google Map plugin is being loaded/initialised within my controller.js file via the following:
angular.module('sampleAppNameHere.controllers', ["google-maps".ns()])
.config(['GoogleMapApiProvider'.ns(), function (GoogleMapApi) {
GoogleMapApi.configure({
key: 'MY-KEY-HERE',
v: '3.17',
libraries: 'weather,geometry,visualization'
});
}])
Further down in the controller where I want the Google Map to be loaded from I have the following set-up:
.controller('LocationController', ['$scope', '$http', '$stateParams', '$sce', '$ionicLoading', '$ionicPopup', '$timeout', 'Logger'.ns(), 'GoogleMapApi'.ns(), 'RetrieveAppContent', function($scope, $http, $stateParams, $sce, $ionicLoading, $ionicPopup, $timeout, $log, GoogleMapApi, RetrieveAppContent)
{
function parseLocations(locationID, locationName, regionName)
{
// Retrieve factory function to return AJAX loaded data
RetrieveAppContent.retrieveRemoteContentForApp().then(function(locationObj)
{
// Loop through associative array formed from parsed AJAX data into factory method
angular.forEach(locationObj.locations, function(v, k)
{
if(locationID === v.recordID)
{
// Other content in here bonded to scope
$scope.mapLongitude = v.mapLongitude;
$scope.mapLatitude = v.mapLatitude;
$scope.mapZoom = v.mapZoom;
}
});
GoogleMapApi.then(function(maps)
{
// Alerts placed in here are triggered when the template loads
maps.visualRefresh = true;
$scope.map = { center: {latitude: $scope.mapLatitude, longitude: $scope.mapLongitude }, zoom: $scope.mapZoom };
$scope.options = { scrollwheel: false };
});
});
}
}
The parseLocations function is called shortly afterwards in the above controller and the content is all loaded into the template exactly as intended so no problems there BUT the angular map will not render.
The following segment is from the view where the content for the controller is loaded/displayed and where the map is located:
<ion-view title="{{ locationName }}">
<ion-content class="location-panel" ng-controller="LocationController">
<!-- Render Google Map -->
<div id="map-canvas">
<ui-gmap-google-map center="map.center" zoom="map.zoom"></ui-gmap-google-map>
</div>
I have set the following class within the CSS that the app uses:
.map-canvas,
.angular-google-maps-container {
height: 400px;
}
But I see NO rendering of the map only a white space fixed to the above height.
Can anyone offer any suggestions/heads-up on what might or could be causing the non-rendering of the Map and what steps I might be able to take to rectify this?
My thanks in advance for any help that folk might be able to provide.....and my apologies if the code formatting is a bit wonky! :-/
Check your CSS class
.angular-google-maps-container
should be
.angular-google-map-container.
I believe you have it as maps not map.
First of all thanks to Brad for his answer to my question (the heads up on the CSS class name WAS useful for my most recent attempt in using this package!).
I originally solved this, back in November 2014, by writing my own custom directive which provided the Google Map functionality that I needed.
Since then I've had occasion to use the latest version of the AngularJS Google Maps package (angular-google-maps 2.0.12 2015-01-29) and have implemented this without problem (noting Brad's tip on the class name).
Thanks once again.
Below is my HTML and the code to do a web service call and display the data in ngGrid. The problem is with the route provider, I'm not being able to show the grid in my separate view, but if I do the exact same code without the route provider,and load just that page, it works perfectly fine.
Since I'm very new to angularJS, any suggestions would be appreciated.I've done lot of research but did not work, at least for me. Please consider this if I have missed related post somewhere. Thanks ahead!
<div>
<!--Placeholder for views-->
<div ng-view=""></div>
</div>
//this is what I have in one of my view for grid.
<div class="gridStyle" data-ng-grid="gridOptions">
</div>
/* display/get/call the JSON data from the web service and bind it to the view */
var app = angular.module('salesApp',['ngGrid']);
app.config (['$routeProvider', function ($routeProvider){
$routeProvider
.when('/sales',
{
controller:'salesCtrl',
templateUrl:'Partials/sales.html'
})
.when('/associate',
{
controller:'assocCtrl',
templateUrl:'Partials/associate.html'
})
.otherwise({redirectTo:'/sales'});
}]);
app.controller('salesCtrl', function($scope, $http) {
$http.jsonp('http://some url...')
.success(function (data) {
$scope.sales = data;
});
$scope.gridOptions = {data: 'sales',
columnDefs:[{field:'Region_Num', displayName: 'Region Num'}
],
showGroupPanel: true
};
});
This is an older post; but I was having the same problem. It turns out when I defined the app/Moduile; I was not passing ngGrid in as one of the options:
myApp = angular.module('myApp', ['ngGrid']);
That is clearly not your problem; as I do see the statement in your code; so this answer is probably for other people who find this question via Google.