AngularJS $stateProvider URL results in blank page - angularjs

I'm using angular-ui-router and set up a 2nd controller similar to my 1st one which was working, but the route in the 2nd controller is not properly routing the app. Can someone please tell me where I went wrong?
html for first controller (works properly):
<div style="height: 100%"> <!--took out: ng-if="map.center !== undefined"-->
<ui-gmap-google-map
center='map.center'
zoom='map.zoom'
draggable='map.draggable'
dragging='map.dragging'
refresh='map.refresh'
options='map.options'
events='map.events'
pan='map.pan'>
<ui-gmap-circle
center='map.circle.center'
radius='map.circle.radius'
fill='map.circle.fill'
stroke='map.circle.stroke'
clickable='map.circle.clickable'
draggable='map.circle.draggable'
editable='map.circle.editable'
visible='map.circle.visible'
events='map.circle.events'>
</ui-gmap-circle>
</ui-gmap-google-map>
<script src='//maps.googleapis.com/maps/api/js?key=AIzaSyD_g7xCYEi-U54SYfTXQ_lukRsChkWgjXQ'></script>
</div>
1st controller (works properly ):
(function (window, ng) {
ng.module('app', ['uiGmapgoogle-maps', 'ui.router'])
.config(function ($stateProvider) { //had: , $stateChangeError included in the function parameters, but that caused error
$stateProvider.state('searchRadius', {
url: '/:lat/:lon',
templateUrl: 'searchRadius.html', //changed from index to searchRadius.html
controller: 'MapsCtrl',
});
})
.controller('MapsCtrl', ['$scope', "uiGmapLogger", "uiGmapGoogleMapApi", "$interval", "$state", "$stateParams",
function ($scope, $log, GoogleMapApi, $interval, $state, $stateParams) {
$log.currentLevel = $log.LEVELS.debug;
var center = { latitude: parseFloat($stateParams.lat), longitude: parseFloat($stateParams.lon) };
alert(JSON.stringify(center));
Object.freeze(center); //caused TypeError: Cannot assign to read only property ('latitude') ...
console.log($stateParams);
$scope.map = {
center: center,
pan: false,
zoom: 16,
refresh: false,
events: {},
bounds: {}
};
$scope.map.circle = {
id: 1,
center: center,
radius: 500, //(current time - date lost)*km/hour
stroke: {
color: '#08B21F',
weight: 2,
opacity: 1
},
fill: {
color: '#08B21F',
opacity: 0.5
},
geodesic: false, // optional: defaults to false
draggable: false, // optional: defaults to false
clickable: true, // optional: defaults to true
editable: false, // optional: defaults to false
visible: true, // optional: defaults to true
events: {
dblclick: function () {
$log.debug("circle dblclick");
},
radius_changed: function (gObject) {
var radius = gObject.getRadius();
$log.debug("circle radius radius_changed " + radius);
}
}
}
//Increase Radius:
$interval(function(){
$scope.map.circle.radius += 30; //dynamic var
}, 1000); //end of interval function
} ]); //end of controller
})(window, angular);
2nd html (blank page):
<!--Add ability to input location as address-->
<div>
<ui-gmap-google-map
center='map.center'
zoom='map.zoom'
draggable='map.draggable'
dragging='map.dragging'
refresh='map.refresh'
options='map.options'
events='map.events'
pan='map.pan'>
<ui-gmap-circle
center='map.circle.center'
radius='map.circle.radius'
fill='map.circle.fill'
stroke='map.circle.stroke'
clickable='map.circle.clickable'
draggable='map.circle.draggable'
editable='map.circle.editable'
visible='map.circle.visible'
events='map.circle.events'>
</ui-gmap-circle>
</ui-gmap-google-map>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDWKJRXSux3dAdEYOYqjkoi2MCW8dutFbY&callback=initMap">
</script>
</div>
2nd controller (results in blank page with no errors):
(function (window, ng) {
ng.module('app', ['uiGmapgoogle-maps', 'ui.router'])
.config(function ($stateProvider) { //had: , $stateChangeError included in the function parameters, but that caused error
$stateProvider.state('getLocation', {
url: '/getLocation',
templateUrl: 'getlocation.html', //changed from index to searchRadius.html
controller: 'GetlocationCtrl',
});
})
.controller('GetlocationCtrl', ['$scope', "uiGmapLogger", "uiGmapGoogleMapApi", "$state", "$stateParams",
function ($scope, $log, GoogleMapApi, $state, $stateParams) {
$log.currentLevel = $log.LEVELS.debug;
var center = { latitude: 49.22, longitude: -122.66 }; //default center
alert(JSON.stringify(center));
console.log($stateParams);
$scope.map = {
center: center,
pan: false,
zoom: 16,
refresh: false,
events: {},
bounds: {}
};
$scope.map.circle = {
id: 1,
center: center,
radius: 500, //(current time - date lost)*km/hour
stroke: {
color: '#08B21F',
weight: 2,
opacity: 1
},
fill: {
color: '#08B21F',
opacity: 0.5
},
geodesic: false, // optional: defaults to false
draggable: false, // optional: defaults to false
clickable: true, // optional: defaults to true
editable: false, // optional: defaults to false
visible: true, // optional: defaults to true
events: {
dblclick: function () {
$log.debug("circle dblclick");
},
radius_changed: function (gObject) {
var radius = gObject.getRadius();
$log.debug("circle radius radius_changed " + radius);
}
}
}
} ]); //end of controller
})(window, angular);

(i) You are using $routerProvider which is not necessarily required
(ii) Also when i check your code, you are loading the first module after loading the 2nd controller. Place your scripts like this in index.html ,
<script src="searchRadius.js"></script>
<script src="getLoc.js"></script>

Related

ui-calendar tooltip function not working

calendar to display a calendar and set of events(events being hardcoded as of now).But when i hover on the event the tooltip is not displayed.I searched for many answers online and none worked for me ,Everything else except tooltip is working.Please help.Following is my js code
var app = angular.module('myApp', ['ui.calendar', 'ui.router']);
app.controller('myNgController', ['$scope', '$http', 'uiCalendarConfig', function($scope, $http, uiCalendarConfig) {
$scope.SelectedEvent = null;
var isFirstTime = true;
$scope.events = [];
$scope.eventSources = [$scope.events];
$scope.events.push({
title: "event",
description: "jahsojoaisjjoijaso",
start: new Date("2017-05-03"),
end: new Date("2017-05-03"),
allDay: false,
stick: false
});
$scope.uiConfig = {
calendar: {
height: 450,
editable: false,
displayEventTime: false,
header: {
left: 'month basicWeek basicDay agendaWeek agendaDay',
center: 'title',
right: 'today prev,next'
},
eventClick: function(event) {
$scope.SelectedEvent = event;
},
eventAfterAllRender: function() {
if ($scope.events.length > 0 && isFirstTime) {
//Focus first event
uiCalendarConfig.calendars.myCalendar.fullCalendar('gotoDate', $scope.events[0].start);
isFirstTime = false;
}
}
}
};
$scope.eventRender = function( event, element, view ) {
element.attr({'tooltip': event.title,
'tooltip-append-to-body': true});
$compile(element)($scope);
};
}]);
and if i try the following code the whole event disappears.The event is no more displayed on the calender
var app = angular.module('myApp', ['ui.calendar', 'ui.router']);
app.controller('myNgController', ['$scope', '$http', 'uiCalendarConfig', function($scope, $http, uiCalendarConfig) {
$scope.SelectedEvent = null;
var isFirstTime = true;
$scope.events = [];
$scope.eventSources = [$scope.events];
$scope.events.push({
title: "event",
description: "jahsojoaisjjoijaso",
start: new Date("2017-05-03"),
end: new Date("2017-05-03"),
allDay: false,
stick: false
});
$scope.uiConfig = {
calendar: {
height: 450,
editable: false,
displayEventTime: false,
header: {
left: 'month basicWeek basicDay agendaWeek agendaDay',
center: 'title',
right: 'today prev,next'
},
eventClick: function(event) {
$scope.SelectedEvent = event;
},
eventAfterAllRender: function() {
if ($scope.events.length > 0 && isFirstTime) {
//Focus first event
uiCalendarConfig.calendars.myCalendar.fullCalendar('gotoDate', $scope.events[0].start);
isFirstTime = false;
}
},
eventRender : function( event, element, view ) {
element.attr({'tooltip': event.title,
'tooltip-append-to-body': true});
$compile(element)($scope);
}
}
};
}]);
and the html code
<h1> calendar</h1>
<div ng-controller="myNgController">
<div class="row">
<div class="col-md-8">
<div id="calendar" ui-calendar="uiConfig.calendar" ng-model="eventSources" calendar="myCalendar"></div>
</div>
<div class="col-md-4">
<div class="alert alert-success" style="margin-top:50px" ng-controller="MyDbController">
<h2 style="margin-top:0px;text-align:center;" ng-repeat="elem in data"> {{elem.balance}} Available </h2>
<a ui-sref="apply" onclick="closeNav()" class="btn btn-success" role="button" style="display: block; margin: 0 auto;" >Reques(s)</a>
</div>
</div>
</div>
</div>
updated code as per answer ..
var app = angular.module('myApp', ['ui.calendar', 'ui.router']);
app.controller('myNgController',['$scope', '$timeout', '$http', '$compile', 'uiCalendarConfig', function($scope, $timeout, $http, $compile, uiCalendarConfig){
$scope.SelectedEvent = null;
var isFirstTime = true;
$scope.events = [];
$scope.eventSources = [$scope.events];
$scope.events.push({
title: "event",
description: "jahsojoaisjjoijaso",
start: new Date("2017-05-03"),
end: new Date("2017-05-03"),
allDay: false,
stick: false
});
$scope.uiConfig = {
calendar: {
height: 450,
editable: false,
displayEventTime: false,
header: {
left: 'month basicWeek basicDay agendaWeek agendaDay',
center: 'title',
right: 'today prev,next'
},
eventClick: function(event) {
$scope.SelectedEvent = event;
},
eventRender : function( event, element, view ) {
element.attr({'tooltip': event.title,
'tooltip-append-to-body': true});
$compile(element)($scope);
},
eventAfterAllRender: function() {
if ($scope.events.length > 0 && isFirstTime) {
//Focus first event
$timeout(function(){
uiCalendarConfig.calendars.myCalendar.fullCalendar('gotoDate', $scope.events[0].start);
isFirstTime = false;
});
}
}
}
};
You must set that function in the calendar configuration definition (Reference):
$scope.uiConfig = {
calendar: {
eventRender: $scope.eventRender,
... reset of the configuration
}
}
Don't forget to inject $compile to your controller:
app.controller('myNgController', ['$scope', '$http', '$compile', 'uiCalendarConfig', function($scope, $http, $compile, uiCalendarConfig) {
As for our discussion in the comments - You're getting "TypeError: Cannot read property 'fullCalendar' of undefined" error. Try the following
Inject $timeout to the controller:
app.controller('myNgController', ['$scope', '$timeout', '$http', '$compile', 'uiCalendarConfig', function($scope, $timeout, $http, $compile, uiCalendarConfig) {
And wrap this line with $timeout:
uiCalendarConfig.calendars.myCalendar.fullCalendar('gotoDate', $scope.events[0].start);
So the final result will be:
$timeout(function() {
uiCalendarConfig.calendars.myCalendar.fullCalendar('gotoDate', $scope.events[0].start);
});
This will make sure that you call fullCalendar only after the view was finished rendering.
And for dessert - Take a look on how you set the tooltip:
element.attr({
'tooltip': event.title,
'tooltip-append-to-body': true
});
Note that it adds tooltip="<title of event> and tooltip-append-to-body="true, but in order to show the tooltip, you need to set a title attribute. Change it to:
element.attr({
'title': event.title,
'tooltip-append-to-body': true
});
I guess that you think it's Bootstrap.UI tooltip (http://angular-ui.github.io/bootstrap/#!#tooltip) so in that case you need to make the necessary changes to implement it correctly. But using title will ensure that while hovering over the event the browser will show you the default tooltip (Using the native HTML "title" attribute).

How to get on-click coordinates on angular google maps?

I'm kind of a newb when it comes to AngularJS and Google's API for maps and I've been trying to get coordinates on click. I'm using this API.
I am getting an error: Uncaught TypeError: Cannot read property 'lat' of undefined
on "console.log(lat);" row
This is my angular controller:
app.controller("agencyController",['$scope', '$log','uiGmapGoogleMapApi', function($scope,$interval, GoogleMapApi){
markers = [],
angular.extend($scope, {
markeri : markers,
map : {
center: bgdcentar,
zoom:13,
options: {
mapTypeId : google.maps.MapTypeId.ROADMAP,
mapTypeControl: true,
streetViewControl: false,
styles: [{"featureType":"administrative","elementType":"labels.text.fill","stylers":[{"color":"#444444"}]},{"featureType":"landscape","elementType":"all","stylers":[{"color":"#f2f2f2"}]},{"featureType":"poi","elementType":"all","stylers":[{"visibility":"off"}]},{"featureType":"road","elementType":"all","stylers":[{"saturation":-100},{"lightness":45}]},{"featureType":"road.highway","elementType":"all","stylers":[{"visibility":"simplified"}]},{"featureType":"road.arterial","elementType":"labels.icon","stylers":[{"visibility":"off"}]},{"featureType":"transit","elementType":"all","stylers":[{"visibility":"off"}]},{"featureType":"water","elementType":"all","stylers":[{"color":"#46bcec"},{"visibility":"on"}]}],
disableDoubleClickZoom: true,
scaleControl: true,
scrollwheel: true,
panControl: true,
streetViewControl: false,
draggable: true,
overviewMapControl: true,
},
events:{
rightclick: function(event){
var lat = event.latLng.lat();
var lng = event.latLng.lng();
console.log(lat);
console.log(lng);
console.log('Stan dodat!');
markers.push();
},
},
},
searchbox : {
template: 'searchbox.tpl.html',
events:{
places_changed: function(searchBox){
},
parentdiv: 'map_canvas'
}
},
});
}]);
And this is a part of my html, the code is included in the controller so don't worry about that:
<div id="map_canvas">
<ui-gmap-google-map center='map.center' zoom='map.zoom' options='map.options' events='map.events' >
<ui-gmap-search-box template="searchbox.template" events="searchbox.events"></ui-gmap-search-box> <!-- search-->
<ui-gmap-markers models="markeri" coords="'self'" icon="'icon'"></ui-gmap-markers> <!-- markeri -->
</ui-gmap-google-map>
</div>
You need to replace:
rightclick: function(event){
//...
}
with:
rightclick: function (map, eventName, events) {
var event = events[0];
//...
}
where
map refers to map object,
eventName - the name of event
events - the list of event listeners
Example
angular.module('appMaps', ['uiGmapgoogle-maps'])
.config(function(uiGmapGoogleMapApiProvider) {
uiGmapGoogleMapApiProvider.configure({
//key: ''
});
})
.controller("mainCtrl", ['$scope', '$log', 'uiGmapGoogleMapApi',
function($scope, $interval, GoogleMapApi) {
angular.extend($scope, {
markers: [],
markerNo: 1,
map: {
center: {
latitude: 42.3349940452867,
longitude: -71.0353168884369
},
zoom: 13,
options: {
},
events: {
rightclick: function(map, eventName, events) {
var event = events[0];
var lat = event.latLng.lat();
var lng = event.latLng.lng();
$scope.$apply(function() {
$scope.markers.push({
latitude: lat,
longitude: lng,
id: $scope.markerNo
});
$scope.markerNo++;
});
},
},
}
});
}
]);
.angular-google-map-container {
position: absolute;
width: 100%;
height: 240px;
}
<script src="https://code.angularjs.org/1.3.14/angular.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.js"></script>
<script src="http://rawgit.com/angular-ui/angular-google-maps/2.0.X/dist/angular-google-maps.js"></script>
<div id="map_canvas" ng-app="appMaps" ng-controller="mainCtrl">
<ui-gmap-google-map center='map.center' zoom='map.zoom' options='map.options' events='map.events'>
<ui-gmap-markers models="markers" coords="'self'" icon="'icon'"></ui-gmap-markers>
</ui-gmap-google-map>
</div>

Call mvc url.action from angular controller

I have this tabset:
<tabset justified="true" class="tabsetnowrap">
<tab ng-repeat="tab in tabshomepage track by $index" heading="{{tab.title}}" ng-click="homePageNavigate(tab.type)" active="tab.active" disabled="tab.disabled">
</tab>
It is created in a angular controller:
$scope.tabshomepage = [];
$scope.tabshomepage.push(
{ title: 'Hjem', type: 'HOM', order: 1, active: true, disabled: false, color: 'black' },
{ title: 'Dirty', type: 'DIR', order: 2, active: false, disabled: false, color: 'purple' },
{ title: 'Dating', type: 'DAT', order: 3, active: false, disabled: false, color: 'green' },
{ title: 'Bloggers', type: 'SOC', order: 4, active: false, disabled: false, color: 'lblue' },
{ title: 'Konto', type: 'ACO', order: 5, active: false, disabled: false, color: 'black' },
{ title: 'Om os', type: 'ABU', order: 6, active: false, disabled: false, color: 'black' },
{ title: 'Kontakt og FAQ', type: 'COF', order: 7, active: false, disabled: false, color: 'black' }
);
When a click is done on a tab, then the homePageNavigate function is performed.
$scope.homePageNavigate = function (type) {
if(type == 'DIR'){
//Perform a #Url.Action("Index", "Dirty", null)"
}
etc...
};
In that functin I want to call a mvc method: #Url.Action("Index", "Dirty", null)", and return a view("index")
What is best way to solve this problem?
Any workarounds? Or a simple solution to this?
I've done something similar before by performing a bit of configuration in angular, through razor, on page load:
<script>
(function () {
angular.module('App').value('paths', {
home: '#Url.Action("Index", "Dirty", null)'
// more paths here
});
})();
</script>
Then you can inject and use paths anywhere within your angular app.
eg. Inside a controller called 'myCtrl`
angular.module('App').controller('myCtrl', ['paths', function(paths) {
// you can use paths.home here
}]);
It's quite simple to invoke ASP.Net MVC Controller action method using AngularJS as follows
In Javascript I wrote
var app = angular.module('MyApp', []);
angular.module('MyApp', [])
.controller('MyController', ['$scope', '$http', function ($scope,
$http) {
$scope.search = function () {
$http({
method: "GET",
url: "/home/GetData"
}).then(function mySuccess(response) {
$scope.name = response.data;
}, function myError(response) {
$scope.name = response.statusText;
});
}
}]);
In HTML part, I wrote
<button ng-click="search()">Get Data</button>
In Controller Action, I wrote return Json("You caught AngularJS", JsonRequestBehavior.AllowGet);

how to get a particular location on google maps with markers from a angular dropdown list

I am trying to do some location search on google maps,its like i am having a angular multi-select drop-down where i am having several locations, if i select a single location or more ,i have to show them on maps using markers,and how to get our current location any suggestions on how to do it please.
Dropdown code
<div class="m-r"
ng-dropdown-multiselect=""
options="locations"
selected-model="search.locations"
extra-settings="multiSelectSettingsFunction"
translation-texts ="locationsTexts"
settings="selectSettings">
</div>
Google maps code
<ui-gmap-google-map center="map.center" refresh="true" zoom="map.zoom" draggable="true" data-tap-disabled="true">
<ui-gmap-window show="map.window.show" coords="map.window.model" options="map.window.options" closeClick="map.window.closeClick()">
<div style="color: black" background-color="#337ab7">
{{map.window.title}}
{{map.window.venue}}
</div>
</ui-gmap-window>
<ui-gmap-markers idkey="marker.id" models="map.markers" coords="'self'" doCluster="false" fit="'true'" icon="'icon'" events="map.markersEvents " options="'options'"></ui-gmap-markers>
</ui-gmap-google-map>
controller.js
app.controller("MainController", [ '$anchorScroll', '$scope', '$http', '$modal', '$log', '$timeout', '$location', '$rootScope', '$window','$mdSidenav' , function ($anchorScroll, $scope, $http, $modal, $log, $timeout, $location, $rootScope, $window,$mdSidenav) {
$scope.searchBack = window.sessionStorage.searchBack;
$scope.search = {
pax: '',
data: '',
locations : [],
distance : []
}
$scope.$watch('search.locations', function(newVal, oldVal){
//console.log(newVal);
//$scope.setSearch();
}, true);
$scope.locationsTexts = {
buttonDefaultText: 'Locations',
dynamicButtonTextSuffix: 'Locations',
}
$scope.multiSelectSettings = {
displayProp: 'locations',
idProp: 'locations',
scrollableHeight: '256px',
scrollable: true,
enableSearch: true,
buttonDefaultText: 'asd',
dynamicButtonTextSuffix: 'Locations',
//showCheckAll: false,
};
$scope.locations = [
{id: 1, label: "kothapet"},
{id: 2, label: "Dsnr"},
{id: 3, label: "Malakpet"},
{id: 4, label: "Chadarghat"},
{id: 5, label: "Koti"},
{id: 6, label: "abids"}
];
Maps Controller
app.controller('MapController2', function($scope, $rootScope, $http) {
var data = {};
data.map = {
zoom: 16,
center: {
latitude: 17.399,
longitude: 78.52
},
markers: [
{
id: 1,
latitude: 17.3762,
longitude: 78.5461,
title: 'Location:Nagole',
venue:'Venue: Ng builders'
},
{
id: 2,
latitude: 17.3710,
longitude: 78.5410,
title: 'Location:Kothapet',
venue:'Venue: A Builders'
},
{
id: 3,
latitude: 17.3688,
longitude: 78.5247,
title: 'Location:Dilsukhnagar',
venue:'Venue: B Builders'
},
{
id: 4,
latitude: 17.3667,
longitude: 78.500,
title: 'Location:Malakpet',
venue:'Venue: C Builders'
}],
markersEvents: {
click: function(marker, eventName, model, arguments) {
console.log('Marker was clicked (' + marker + ', ' + eventName);//+', '+mydump(model, 0)+', '+mydump(arguments)+')');
$scope.map.window.model = model;
$scope.map.window.model = model;
$scope.map.window.title = model.title;
$scope.map.window.venue = model.venue;
$scope.map.window.show = true;
}
},
window: {
marker: {},
show: false,
closeClick: function() {
this.show = false;
},
options: {}, // define when map is ready
title: ''
}
};
//$scope.window = false;
$scope.onMarkerClicked = function (m) {
//this.windowOptions = !this.windowOptions;
console.log('Marker was clicked');
console.log(m);
};
$scope.closeClick = function () {
this.window = false;
};
$scope.map = data.map;
});
1) To resolve location by address name utilize Google Maps Geocoding API, for example:
var resolveAddress = function(address) {
var deffered = $q.defer();
$http({
url: 'http://maps.googleapis.com/maps/api/geocode/json?address=' + address + '&sensor=false',
method: 'GET'
}).
success(function(data) {
deffered.resolve(data);
}).
error(function(error) {
deffered.reject();
});
return deffered.promise;
};
2) For angularjs-dropdown-multiselect component you could utilize events to add events what the directive fires, for example onItemSelect which triggers once the item is selected:
<div class="m-r"
ng-dropdown-multiselect=""
options="locations"
selected-model="search.locations"
translation-texts="locationsTexts"
settings="selectSettings"
events="{ onItemSelect: showItemOnMap }">
</div>
$scope.showItemOnMap = function(item) {
//...
};
The following demo demonstrates how to display markers on map from items selected in angularjs-dropdown-multiselect control
Demo

Angular-nvD3 Pie Chart Not Displaying

I am trying to follow a simple example to make a pie chart but it does not render the chart. Even viewing the source, no chart code appears (only the original directive code). The controller is getting loaded as I do see the log file statement and the title property within the scope. I am not getting any errors to the console and a bit confused at the moment.
Thanks in advance
I am using the latest version of the libraries, added at the index.html file
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.js"> </script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/nvd3/1.8.1/nv.d3.js"> </script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angularjs-nvd3-directives/0.0.7/angularjs-nvd3-directives.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/nvd3/1.8.1/nv.d3.css"/>
Chart.html
<div >
<div ng-controller="chartsController" >
<div>
{{title}}
</div>
<nvd3ChartDirectives options="options" data="data" id="chartId" config="config" class="with-3d-shadow with-transitions">
</nvd3ChartDirectives>
</div>
</div>
Index.js
var app = angular.module('seApp', ['ngRoute', 'ngResource', 'ngMessages', 'ngAnimate', 'ui.bootstrap', 'smart-table', 'nvd3ChartDirectives']);
(Injecting as nvd3 does not work).
Chart.js
app.controller('chartsController', ['$scope', '$log', function($scope, $log) {
$scope.title = 'Chart Title';
$log.info ("Create Chart");
$scope.options = {
chart: {
type: 'pieChart',
height: 500,
width: 600,
x: function(d){return d.key;},
y: function(d){return d.y;},
showLabels: true,
transitionDuration: 500,
labelThreshold: 0.01,
legend: {
margin: {
top: 5,
right: 35,
bottom: 5,
left: 0
}
}
}
}
$scope.config = {
visible: true, // default: true
extended: false, // default: false
disabled: false, // default: false
autorefresh: true, // default: true
refreshDataOnly: false, // default: false
deepWatchOptions: true, // default: true
deepWatchData: false, // default: false
deepWatchConfig: true, // default: true
debounce: 10 // default: 10
};
$scope.xFunction = function(){
return function(d){
return d.key;
};
};
$scope.yFunction = function(){
return function(d){
return d.y;
};
};
$scope.data = [
{
key: "435fdfg",
y: 16
},
{
key: "fgfsgsg",
y: 12
},
{
key: "lodfrr",
y: 3
},
{
key: "yuiiyui",
y: 7
},
{
key: "adffd",
y: 4
}
]
}]);
I had a similar problem. After using ng-inspector I found out that the options where not passed in correctly due to a typo).
I did however tried to register the dependency with "nvd3ChartDirectives" but received an exception so I just used nvd3. Maybe this could be a possible problem.
I would recommend doing some debugging with ng-inspector or Batarang and check that the scope is set properly.
BTW, I'm using Angular 1.4.8.

Resources