how to show chars on default page? - html

I page web aplication with index.html file where is my login page. after succes log in I want to load page with routeProvider where i am using charts to draw diagrams . I have Error when i am loading just index.html for logg in not even this page where i am using charts.
my error looks like
Error: Please set height and width for the chart element
i#http://localhost:8080/pos/js/angular-charts.min.js:1:12049
Y/<#http://localhost:8080/pos/js/angular.min.js:70:91
Z#http://localhost:8080/pos/js/angular.min.js:70:149
A#http://localhost:8080/pos/js/angular.min.js:59:203
g#http://localhost:8080/pos/js/angular.min.js:51:299
g#http://localhost:8080/pos/js/angular.min.js:51:316
g#http://localhost:8080/pos/js/angular.min.js:51:316
g#http://localhost:8080/pos/js/angular.min.js:51:316
F/<#http://localhost:8080/pos/js/angular.min.js:50:415
ngViewFillContentFactory/<.link#http://localhost:8080/pos/js/angular-route.js:983:7
Z#http://localhost:8080/pos/js/angular.min.js:70:149
A#http://localhost:8080/pos/js/angular.min.js:59:203
g#http://localhost:8080/pos/js/angular.min.js:51:299
F/<#http://localhost:8080/pos/js/angular.min.js:50:415
I/<#http://localhost:8080/pos/js/angular.min.js:52:283
l#http://localhost:8080/pos/js/angular.min.js:56:293
update#http://localhost:8080/pos/js/angular-route.js:933:25
Pe/this.$get</l.prototype.$broadcast#http://localhost:8080/pos/js/angular.min.js:128:120
commitRoute/<#http://localhost:8080/pos/js/angular-route.js:616:15
f/<#http://localhost:8080/pos/js/angular.min.js:112:20
Pe/this.$get</l.prototype.$eval#http://localhost:8080/pos/js/angular.min.js:125:301
Pe/this.$get</l.prototype.$digest#http://localhost:8080/pos/js/angular.min.js:122:390
Pe/this.$get</l.prototype.$apply#http://localhost:8080/pos/js/angular.min.js:126:56
l#http://localhost:8080/pos/js/angular.min.js:81:169
S#http://localhost:8080/pos/js/angular.min.js:85:301
vf/</D.onload#http://localhost:8080/pos/js/angular.min.js:86:315
<div data-ac-chart="'pie'" data-ac-data="cityData" data-ac-config="cityConf" class="chart ng-isolate-scope" id="chart">
here is my html file where i have charts
<div class="row-fluid maginTopDiv">
<div class="span4">
<h2>City</h2>
<div
data-ac-chart="'pie'"
data-ac-data="cityData"
data-ac-config="cityConf"
class="chart" id="chart">
</div>
</div>
<div class="span4">
<h2>Type</h2>
<div
data-ac-chart="'pie'"
data-ac-data="termTypeData"
data-ac-config="termTypeConf"
class="chart" id="chart">
</div>
</div>
<div class="span4">
<h2>Program ID</h2>
<div
data-ac-chart="'pie'"
data-ac-data="programIdData"
data-ac-config="programIdConf"
class="chart" id="chart">
</div>
</div>
</div>
here is my css content for this divs
.chart{
width: 100%;
height: 200px;
}
my config for routing
app.config(function($routeProvider){
$routeProvider
.when('/', {
templateUrl: 'home.htm',
controller: 'mainController'
})
.when('/dashboard', {
templateUrl: 'home.htm',
controller: 'mainController'
})
.when('/archive',{
templateUrl: 'problemArchive.htm',
controller: 'mainController'
})
.otherwise({
templateUrl: 'home.htm',
controller: 'mainController'
});
});
and in controller i am defining data for this charts after successuly logg in and after login i am getting data on the page except this charts.
why i have this errors when i even not loading this page i just have index.html page where i am not using charts, just after log in

Related

router stopped working after an update

I used to have the attached code working just fine, but then an update caused it to stop working. I was not able to make the adjustments so hopefully someone here has gone through it. The last block after the HTML is just smarty code to include the js file. The URL I am getting is: mySite.com/policies#!/#refund
which does not load anything. If I manually delete the second # to make it /policies#!/refund it does work.
This is the js file:
var app = angular.module('myApp', ['ngRoute', 'ui.bootstrap', 'dialogs.main',
'summernote', 'angular-loading-bar', 'ngAnimate', 'fiestah.money', 'ui.ace',
'ui.select', 'ngCart']);
app.config(function ($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
templateUrl: '/templates/main-app/policy/policy-reviews.tpl',
controller: 'mainCtrl'
})
.when('/reviews', {
templateUrl: '/templates/main-app/policy/policy-reviews.tpl',
controller: 'mainCtrl'
})
.when('/currency', {
templateUrl: '/templates/main-app/policy/policy-currency.tpl',
controller: 'mainCtrl'
})
.when('/refund', {
templateUrl: '/templates/main-app/policy/policy-refund.tpl',
controller: 'mainCtrl'
});
});
app.controller('mainCtrl', function ($scope, $rootScope, $filter, $http, $location, dialogs) {
console.log("in ctrl");
});
This is the template:
<div ng-controller="mainCtrl">
<div class="act-dash">
<nav class="navbar-default content-header blue" role="navigation" style="position:relative;">
<!-- We use the fluid option here to avoid overriding the fixed width of a normal container within the narrow content columns. -->
<div id="admin-collapse" class="pad-left-fix" style="bottom:0px;">
<div class="container"><h1>Terms and Policies</h1></div>
<ul class="nav navbar-nav" style="position:relative; bottom:0px">
<li><span class="glyphicon glyphicon-eye-open"> </span>Comments and Reviews</li>
<li><span class="glyphicon glyphicon-usd"> </span>Currency Conversion</li>
<li><span class="glyphicon glyphicon-usd"> </span>Refund Policy</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</nav>
<div class="content narrow-content margin-fix">
<div class="row margin-fix margin-bottom-fix div-table" style="width:100%;">
<div class="col-md-12 pad-left-fix pad-right-fix div-table-cell">
<div style="text-align: left;">
<div id="main">
<!-- angular templating -->
<!-- this is where content will be injected -->
<div ng-view>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{assign var="extra_js" scope="global" value="
<script type=\"text/javascript\" src=\"/js/angular-apps/policy.js\">
</script>
"}
You can Add Following line of code in your app.config, Just below
$routeProvider and see if it will work. Before run Please clear cache
and coockies on your browser.
$locationProvider.hashPrefix('');

Unable to position the div content to center of page

I am using angulars UI router to load each page separately. I have header navbar and sidebar inside header.html and main-content(dynamic) in login.html
The login html page is getting overlapped with sidebar and footer because it is loaded separately. How do I fix this? I applied wrapper(custom css) class but it didn't affect the layout at all.
Here the link: http://angularspring-management999.rhcloud.com/default.html
Sample code:
<body>
<div id="wrap">
<!--header-->
<div ui-view="header"></div>
<!--sidebar-->
<div ui-view="sidebar"></div>
<!--main content-->
<div ui-view="content"></div>
</div>
<!--footer-->
<div ui-view="footer"></div>
</body>
States:
myApp.config(function ($stateProvider, $locationProvider, $urlRouterProvider, $httpProvider) {
// For any unmatched url, redirect to /login
$urlRouterProvider.otherwise("/Login");
var header = {
templateUrl: 'views/Header.html',
controller: function ($scope) {
}
};
var sidebar = {
templateUrl: 'views/SideBar.html',
controller: function ($scope) {
}
};
var footer = {
templateUrl: 'views/Footer.html',
controller: function ($scope) {
}
};
// Now set up the states
$stateProvider
.state('Login', {
url: "/Login",
views: {
'header': header,
'sidebar': sidebar,
content: {
templateUrl: 'views/Login.html',
controller: function ($scope) {
}
},
'footer': footer
}
});
Wouldn't something like this work using bootstraps grid?
<div class="row">
<div class="col-xs-3">
<div ui-view="view-1"></div>
</div>
<div class="col-xs-9">
<div ui-view="view-2"></div>
</div>
</div>
I've only ever used 1 ui-view element in my apps, and then created custom directives for this type of functionality. But according to the docs your way should be fine. Just be careful that sometimes ui-view can override certain template properties.

AngularJS Filter is not working as expected

Right side Bajra atta, Besan, Corn Flour .. are subcategories.
Index.html
<body>
<div class='container'>
<div class='row'>
<div class='col-md-4'></div>
<!-- Serach Area -->
<div class='col-md-5'>
<input style="margin-top:5px;" type="text" ng-model="SearchText" placeholder="Search for more than 10,000 products..." class='form-control' size="50">
</div>
<div class='col-md-1'></div>
<div class='col-md-2'>
<a id="top_login" href="#Login" style="position:absolute; margin-top:15px; color:#FFFCBA">
<strong>LOGIN </strong>
</a>
</div>
</div>
</div>
<div ng-controller="MainCtrl">
<div class='container'>
<div class='row'>
<div class='col-md-2 Name'>
<!-- Super Categories-->
</div>
<div class='col-md-7'> </div>
<div class='col-md-2'>
<!--SC Cart-->
</div>
<div class='col-md-1'></div>
</div>
</div>
<div id="middle" class='container'>
<div class='row'>
<div id="left" class="col-md-2">
<!-- categoris and sub categories -->
</div>
<div id="right" class="col-md-6">
<div ng-view></div>
</div>
</div>
</div>
</div>
<div id="footer">
<!-- Footer -->
</div>
</body>
products.html
<div class='box' ng-repeat="product in ProductService.Products | filter:SearchText | filter:FilterExpr:true| orderBy:'ProductName'">
<!-- Display filtered Products -->
</div>
ProductsController
sampleApp.controller('ProductsController', function ($scope, $routeParams, $log, $rootScope, ProductService) {
$scope.SCId = $routeParams.SCId;
$scope.ChangeFilter = function() {
if ($routeParams.SCId) {
$scope.FilterExpr = {'SubCategoryID': $routeParams.SCId.toString()};
}
};
$scope.ChangeFilter();
});
config Code
sampleApp.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/Login', {
templateUrl: 'templates/ShowLogin.html',
controller: 'LoginController'
}).
when('/ShoppingCart', {
templateUrl: 'templates/ShoppingCart.html',
controller: 'ShoppingCartController'
}).
when('/Products/:SCId', {
templateUrl: 'templates/Products.html',
controller: 'ProductsController'
}).
otherwise({
redirectTo: '/Products/38'
});
}]);
When user clicks on subcategory, products of that subcategory is listed.
As otherwise is redirectTo: '/Products/38' products of subcategory 38 is listing initially.
I'm facing the following problems:
when user start typing in search box, filter:SerachText is applied on displayed subcategory products. But at this moment i want filter:SerachText to be apply on all the products (Not only on selected subcategory products)
Filter is not applying, if we are in some other routed page say login page. I want as soon as user start typing in search Box products.html and productsController to be activate.
When user has inputted something in search Box, and clicks on sub category, not all the products of that subcategory is listing because filter:SerachText is applied here. In this case i dont want to apply filter:SerachText filter
Can please some one help me to fix all these issues. I've tried all the combinations and permutations, but no luck. I'm also Ok if any architecture change is required that can make the things better.
Have you ever tried to hoist the SearchText filter scope to $parent.SearchText??
I guess, a superior scope ($parent or $rootScope) in your filter could work.
BTW: It works for me, 'cause it seems that ng-include does a local scope for each HTML to render, even in the same page.
P.D: Sorry for my English, greetings from Venezuela :D

Semantic-ui menu and Angularjs ngRoute

I am using the Semantic-UI with AngularJS and I have a problem with semantic-ui menu.
In the index.html file I define the main menu:
<div class="ui inverted tiered menu">
<a class="active item" href="#/login">
<i class="sign in icon"></i> Login
</a>
<div class="ui dropdown item">
<i class="users icon"></i> TEST <i class="icon dropdown"></i>
<div class="menu">
<a class="item" href="#/test/test1"><i class="add icon"></i>Dodaj</a>
</div>
</div>
</div>
...
<div ng-view></div>
In app.js I have:
hrmApp.config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/login', {
templateUrl: '/login.html',
controller: 'LoginController'
}).
when('/comment', {
templateUrl: '/test.html',
controller: 'TestController'
}).
otherwise({
redirectTo:'/login'
});
}]);
When I navigate to the site using /test/test1 then the dropdown menu works however when I navigate to the site using /login and then reload page (ctrl+r) then the dropdown menu doesnt work. What may be the cause of this problem?
I solved the problem. I have multiple controllers and ui.dropdown was initalized only in one of them using code presented below:
$('.ui.dropdown').dropdown();
Adding this code in other controllers solved it.

AngularJS - Custom directives - one gives error "Template must have exactly one root element" while other works

here is my index.html
<html ng-app="dempApp">
<head>
<!-- CSS -->
</head>
<body>
<div ng-switch on="templateHeader">
<div ng-switch-when="login">
<div loginheader></div>
</div>
<div ng-switch-when="home">
<div homeheader></div>
</div>
</div>
</body>
<!-- JS scripts -->
</html>
My app.js has the directives
demoClientApp.directive('loginheader', function () {
return {
restrict: 'A',
replace: true,
templateUrl:'views/loginheader.html'
}
})
demoClientApp.directive('homeheader', function () {
return {
restrict: 'A',
replace: true,
templateUrl:'views/homeheader.html'
}
})
loginheader.html is like following
<div class="main-container">
<div class="main-content">
<div class="row">
<div class="col-sm-10 col-sm-offset-1">
<div class="login-container">
<div class="center">
<h1>
<span class="blue">DemoApplication</span>
</h1>
</div>
<div class="position-relative">
<div ng-view></div>
</div><!-- /position-relative -->
</div>
</div><!-- /.col -->
</div><!-- /.row -->
</div>
</div><!-- /.main-container -->
It has ng-view inside and similarly for homeheader directive I have another html file which also has ng-view.
Based on path, I am setting value of templateHeader and its switching the directive. But the page is blank now and shows error.
Error: Template must have exactly one root element. was: <div class="main-container">
<div class="main-container">
<div class="main-content">
<div class="row">
<div class="col-sm-10 col-sm-offset-1">
<div class="login-container">
<div class="center">
<h1>
<span class="blue">DemoApplication</span>
</h1>
</div>
<div class="position-relative">
<div ng-view></div>
</div><!-- /position-relative -->
</div>
</div><!-- /.col -->
</div><!-- /.row -->
</div>
</div><!-- /.main-container -->
If I don't use the loginheader directive and use the html directly, it is working fine and the other homeheader directive is working. Why is that?
How to solve it?
UPDATE 1
It is working. But the problem is when the path is just localhost:9000 it is not redirecting to login. Earlier it used to route to login if the user enters a wrong path or not logged in. So now when I just type the url localhost:9000, it is showing the blank page and the error. Here is how I route.
var demoClientApp=angular.module('demoClientApp', ['ngCookies']);
demoClientApp.config(['$routeProvider', '$locationProvider',
function($routeProvider,$locationProvider) {
$routeProvider
.when('/login', {
templateUrl: 'login.html',
controller: 'LoginController'
})
.when('/register', {
templateUrl: 'register.html',
controller: 'RegisterController'
})
.when('/home', {
templateUrl: 'views/dashboard.html',
controller: 'DashboardCtrl'
})
.otherwise({
redirectTo: '/login'
});
}]);