Bootstrap Column not working as Expected - angularjs

I am having a bootstrap div with 3 columns as given in the html below and when i have a select control in the first div of the row, the remaining div's don't show up. but if i comment out the same and check with hello world text. All columns show up just like it should be.
not sure what is that i am missing, hence looking out for a new set of eyes to point out what is wrong. :)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<div class="container-fluid">
<div style="text-align:center">
<h1>Wind Monitoring System </h1>
</div>
<div class="row">
<div class="col-md-4" style="background:blue">
<span>Hello World1</span>
<!--<div>
<select id="states" ng-model="selectedState" ng-change="getCities()" size="3" ng-options="state.Name for state in states" />
</div>-->
</div>
<div class="col-md-4" style="background:blue">
<span>Hello World2</span>
</div>
<div class="col-md-4" style="background:blue">
<span>Hello World3</span>
<!--<select id="city" ng-show="selectedState != null" ng-model="selectedCity" size="3" style="height:200px;width:200px" ng-options="city.city for city in cities | filter : {State:selectedState.Name}" />-->
</div>
</div>
</div>

If I'm not mistaken the select tags should be as such <select></select> I believe you are supposed to be binding your options not your <select> tags.
Check this link out
Okay here you go
HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
<div ng-app="app">
<div class="container-fluid">
<div style="text-align:center">
<h1>Wind Monitoring System </h1>
</div>
<div class="row">
<div class="col-md-4" style="background:blue">
<span>Hello World1</span>
<div ng-controller="Test">
<select ng-model="selectedState" size="3" ng-options="item for item in items"></select>
</div>
</div>
<div class="col-md-4" style="background:blue">
<span>Hello World2</span>
</div>
<div class="col-md-4" style="background:blue">
<span>Hello World3</span>
</div>
</div>
</div>
</div>
JavaScript
var app = angular.module('app',[]);
app.controller('Test',function($scope){
$scope.items = ['one','two','three','four']
});
I believe all I did was add the closing tag.

Related

Can I prevent bootstrap popover overflow from it's wrapper?

I am using bootstrap's popover, but I don't want the popover overflow it's wrapper, any ideas?
Demo on Plunker
<!DOCTYPE html>
<html>
<head>
<script src="https://code.angularjs.org/1.5.5/angular.js" data-semver="1.5.5" data-require="angularjs#1.5.5"></script>
<script data-require="ui-bootstrap#*" data-semver="1.3.2" src="https://cdn.rawgit.com/angular-ui/bootstrap/gh-pages/ui-bootstrap-tpls-1.3.2.js"></script>
<script data-require="bootstrap.js#*" data-semver="3.3.6" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.css" rel="stylesheet" data-semver="3.3.6" data-require="bootstrap-css#*" />
<script src="controller.js"></script>
<script id="calendar.html" type="text/ng-template">
<uib-datepicker ng-model="date" show-weeks="false">
</datepicker>
</script>
<link rel="stylesheet" href="main.css">
<link rel="stylesheet" href="popover.css">
</head>
<body>
<div ng-app="my-app" ng-controller="controller">
<div class="card">
<div class="card-panel">
<div class="card-body">
<div class="row">
<p>BAbababababbabababababababababababababbabaabbabaabababbBAbababababbabababababababababababababbabaabbabaabababbBAbababababbabababababababababababababbabaabbabaabababb</p>
</div>
</div>
</div>
</div>
<div class="card">
<div class="card-panel">
<div class="card-body">
<div class="row">
<div class="col-xs-12" style="text-align:center;">
<h2>Here is a list a weapons</h2>
</div>
</div>
<div class="row" ng-repeat="item in weaponItems">
<div class="col-xs-12">
<div class="col-xs-6" ng-click="selectItem(item)" uib-popover-template="'popover.html'" popover-is-open="isOpen && item === selectedItem" popover-trigger="click" popover-placement="auto right">
<div class="panel">
<div class="panel-body" style="min-height:120px;">
<div><b>Category:</b> {{item.title}}</div>
<p><b>Desc:</b> {{item.desc}}</p>
</div>
</div>
</div>
<div class="col-xs-6">
<div class="panel" style="text-align:center;">
<img src="{{item.img}}" height="120px" width="auto">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
I think I don't make my question clear, see the attached imagethe red line surrounded area is the card-panel area, and the green line surrounded is the popover. Here, I don't want the popover beyond the panel area.
Declare word-wrap on the overflowing element.
.card-body p{
word-wrap: break-word;
}

Setting Angular variable in HTML whilst using ng-repeat

I have the following code which works great:
<div class="progress progress-striped active">
<div class="progress-bar progress-bar-success" style="width: {{(p.availableIpAddressCount/p.totalIpAddressCount)*100|number:0}}%;background-color: #5cb85c">
{{(p.availableIpAddressCount/p.totalIpAddressCount)*100|number:0}}
</div>
</div>
However, as you can see, I am repeating {{(p.availableIpAddressCount/p.totalIpAddressCount)*100|number:0}} alot and I therefore would like to assign it to angular variable. I would also like to do an NG-switch on the result. This is what I have tried
<div class="progress progress-striped active" ng-init = "barPercentage= {{(p.availableIpAddressCount/p.totalIpAddressCount)*100|number:0}}">
<div ng-switch="barPercentage">
<div ng-switch-when=">=0" class="progress-bar progress-bar-success" style="width: {{barPercentage}}%;background-color: #5cb85c">
{{(p.availableIpAddressCount/p.totalIpAddressCount)*100|number:0}}
</div>
</div>
</div>
However this doesn't work at all but I'm unsure why. I get no errors in the console.
Any ideas?
var app = angular.module('demo', []);
app.controller('DemoCtrl', DemoCtrl);
DemoCtrl.$inject = ['$scope'];
function DemoCtrl($scope) {
// you can change this as you like. its just for demo purposes.
$scope.p = {
"availableIpAddressCount": 100,
"totalIpAddressCount": 70
}
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script data-require="ui-bootstrap-tpls#*" data-semver="1.2.5" src="https://cdn.rawgit.com/angular-ui/bootstrap/gh-pages/ui-bootstrap-tpls-1.2.5.js"></script>
<script data-require="jquery#2.2.0" data-semver="2.2.0" src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<link data-require="bootstrap#3.3.2" data-semver="3.3.2" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
<script data-require="bootstrap#3.3.2" data-semver="3.3.2" src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<script data-require="ui-bootstrap#1.3.2" data-semver="1.3.2" src="https://cdn.rawgit.com/angular-ui/bootstrap/gh-pages/ui-bootstrap-tpls-1.3.2.js"></script>
<div ng-app="demo" ng-controller="DemoCtrl">
<!--using ng-if -->
<div class="progress progress-striped active" ng-init="barPercentage= (p.availableIpAddressCount/p.totalIpAddressCount*100) | number:0">
<div ng-if="barPercentage>=0" class="progress-bar progress-bar-success" style="width: {{barPercentage | number: 0}}%;background-color: #5cb85c">
{{barPercentage |number:0}}
</div>
</div>
<!-- using ng-switch -->
<div class="progress progress-striped active" ng-init="barPercentage= (p.availableIpAddressCount/p.totalIpAddressCount*100) | number:0">
<div ng-switch on="(barPercentage>=0)">
<div ng-switch-when="true">
<div class="progress-bar progress-bar-success" style="width: {{barPercentage | number: 0}}%;background-color: #5cb85c">
{{barPercentage |number:0}}
</div>
</div>
<div ng-switch-default>
<!-- code to render the regular block -->
</div>
</div>
</div>
</div>
I would highly suggest that you create a variable in your controller and expose it to the scope.
$scope.barPercentage = (p.availableIpAddressCount/p.totalIpAddressCount)*100 ;
The way to do it in your html is effectively ng-init, but it's highly unrecommended in the docs.
Note that there are no AngularJS variables, rather a JavaScript object called $scope that is exposed to your template.

AngularJS doesn't work Visual Studio?

I have just started with learning AngularJS and everthing works great before I started to write some easy controller method and method doesn't work even i include ng-contoller I tried to include it as separated js file but that also doens't work I am new to angularJS so I would appreciate any help I also tried with notped++ to do the same but doesn't work this is my code;
<!DOCTYPE html>
<html data-ng-app="">
<head>
<title></title>
<meta charset="utf-8" />
<script src="Scripts/jquery-1.9.1.min.js"></script>
<link href="Content/bootstrap.min.css" rel="stylesheet" />
<script src="Scripts/bootstrap.min.js"></script>
<script src="Scripts/angular.min.js"></script>
</head>
<body>
<div class="container" data-ng-controller="AppController">
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#nav-toggle">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">Contact Manager</a>
</div>
<div class="collapse navbar-collapse" id="nav-toggle">
<ul class="nav navbar-nav">
<li class="alert-success">Browse</li>
<li>Add contacts</li>
</ul>
<form class="navbar-form navbar-right" role="search">
<input type="text" class="form-control" placeholder="Search"/>
</form>
</div>
</nav>
<div class="page-header">
<h2>Prvo poglavlje <small>Hello world</small></h2>
</div>
<div class="container">
<div class="jumbotron">
<h1>Hello, {{name||"World"}}</h1>
<input type="text" class="form-control input-lg" data-ng-model="name" />
</div>
<div class="row">
<div class="col-sm-8 pull-right hidden-lg" >
<div class="row">
<div class="col-sm-6">
<p>Prvi</p>
</div>
<div class="col-sm-6">
<p>Drugi</p>
</div>
</div>
</div>
<div class="col-sm-4 pull-left show" >
This is our sidebar
</div>
</div>
<div class="row">
<div class="col-md-8">
<button ng-click="clickHandler()">Click me</button>
</div>
</div>
</div>
</div>
<script>
function AppController($scope) {
$scope.clickHandler = function () {
window.alert("Clicked");
};
}
</script>
</body>
</html>
You have to define a module before instantiate your controller:
angular
.module('app', [])
.controller('AppController', AppController);
AppController.$inject = ['$scope'];
function AppController($scope) {
$scope.clickHandler = function () {
window.alert("Clicked");
};
}
<!DOCTYPE html>
<html ng-app="app">
<head>
<title></title>
<meta charset="utf-8" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.min.js"></script>
</head>
<body>
<div class="container" ng-controller="AppController">
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#nav-toggle">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">Contact Manager</a>
</div>
<div class="collapse navbar-collapse" id="nav-toggle">
<ul class="nav navbar-nav">
<li class="alert-success">Browse</li>
<li>Add contacts</li>
</ul>
<form class="navbar-form navbar-right" role="search">
<input type="text" class="form-control" placeholder="Search" />
</form>
</div>
</nav>
<div class="page-header">
<h2>Prvo poglavlje <small>Hello world</small></h2>
</div>
<div class="container">
<div class="jumbotron">
<h1>Hello, {{name||"World"}}</h1>
<input type="text" class="form-control input-lg" data-ng-model="name" />
</div>
<div class="row">
<div class="col-sm-8 pull-right hidden-lg">
<div class="row">
<div class="col-sm-6">
<p>Prvi</p>
</div>
<div class="col-sm-6">
<p>Drugi</p>
</div>
</div>
</div>
<div class="col-sm-4 pull-left show">
This is our sidebar
</div>
</div>
<div class="row">
<div class="col-md-8">
<button ng-click="clickHandler()">Click me</button>
</div>
</div>
</div>
</div>
</body>
</html>
You have not defined the module anywhere in the code,
In View:
<html ng-app="myApp">
In JS:
var app = angular.module("myApp", []);
Working Sample
You need to include the angular module. Angular works with modules.
Controllers are part of module.
Try something like this:
app = angular.module("myApp", []);
app. Controller(...);
And use this module in your html like
<html ng-app="myApp">
Also,
The controller declaration you are using is old.
Try this:
app.controller('controllerName', ['$scope', function($scope){...}]);

Two inline Bootstrap datepickers not fitting bootstrap grid column and panel

I am a newbie when it comes to frontend. I have been working on a little single page angularjs app and I came across an issue. On my page, I need two inline datepickers. I chose angular-ui-bootstrap datepickers. They render in an odd way veiling each other:
veiling datepickers
Here's part of my HTML code:
<div class="row">
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
<h4>Date range</h4>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-5">
<div style="display: inline-block;">
<uib-datepicker ng-model="dateFrom" starting-day="1" max-date="dateTo" show-weeks="false"></uib-datepicker>
</div>
<div>
<label>Date from {{dateFrom | date: "dd/MM/yyyy"}}</label>
</div>
</div>
<div class="col-md-5 ">
<div style="display: inline-block;">
<uib-datepicker ng-model="dateTo" starting-day="1" min-date="dateFrom" show-weeks="false"></uib-datepicker>
</div>
<div>
<label>Date to {{dateTo | date: "dd/MM/yyyy"}}</label>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<label> Additional Info</label>
</div>
Do you have any idea how to make them fit the panel normally without this veiling?
Before I put datepickers into panel div, the display issue was the same. They were tighten together and not fitting the grid column.
Each help will be appreciated
As <uib-datepicker> has a fixed size and cannot be resized according to grid width, you can customize the size of the small buttons (days).
See in the snippet below the .custom-size .btn-sm CSS class:
var app = angular.module('app', ['ui.bootstrap']);
app.controller('MyCtrl', function($scope) {
});
.custom-size .btn-sm {
padding: 4px 8px;
font-size: 11px;
line-height: 1.5;
border-radius: 3px;
}
<!DOCTYPE html>
<html ng-app="app">
<head>
<meta charset="utf-8" />
<title>AngularJS UI Bootstrap</title>
<script data-require="angular.js#1.4.x" src="https://code.angularjs.org/1.4.8/angular.js" data-semver="1.4.8"></script>
<script src="http://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.14.3.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<script src="app.js"></script>
</head>
<body ng-controller="MyCtrl">
<div class="container-fluid">
<h2>AngularJS: UI Bootstrap datepicker</h2>
<div class="row">
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
<h4>Date range</h4>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-6">
<div style="display: inline-block;">
<uib-datepicker ng-model="dateFrom" starting-day="1" max-date="dateTo" show-weeks="false" class="custom-size"></uib-datepicker>
</div>
<div>
<label>Date from {{dateFrom | date: "dd/MM/yyyy"}}</label>
</div>
</div>
<div class="col-md-6">
<div style="display: inline-block;">
<uib-datepicker ng-model="dateTo" starting-day="1" min-date="dateFrom" show-weeks="false" class="custom-size"></uib-datepicker>
</div>
<div>
<label>Date to {{dateTo | date: "dd/MM/yyyy"}}</label>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<label> Additional Info</label>
</div>
</div>
</div>
</body>
</html>

How to configure Twitter Bootstrap for not offset blocks?

I set variable value using AngularJS.
<div class="col-md-5">Cost:</div>
<div class="col-md-7">{{ cost }}</div>
<div class="col-md-5">Total:</div>
<div class="col-md-7">{{ total }}</div>
And I see
Cost: 5
Total: 7
But when cost = "", I see:
Cost: Total:
7
But I want to see:
Cost:
Total: 7
How to configure my HTML?
Surely you could simply add a line break?
<br />
Either that or you could write a script that would test the value of the cost. Why would the cost be = to "" anyway? Surely to have the total there would be a cost?
Try setting the cost = " ", with the space inbetween.
You could also use php I suppose.
You can wrap your line into div.row, like this:
<div class="row">
<div class="col-xs-5">Cost:</div>
<div class="col-xs-7">{{cost}}</div>
</div>
<div class="row">
<div class="col-xs-5">Total:</div>
<div class="col-xs-7">{{total}}</div>
</div>
So now when you will not have value of your model you will still can see your labels in 1 line.
Demo: http://plnkr.co/edit/kSvv1EjXyB7qhXotNEA7?p=preview
There are two things you can do here. First you should be starting a new row element for each row of data, like this:
<div class="container">
<div class="row">
<div class="col-md-5">Cost:</div>
<div class="col-md-7"></div>
</div>
<div class="row">
<div class="col-md-5">Total:</div>
<div class="col-md-7">{{ total }}</div>
</div>
</div>
The next thing you can do is either add &nbsp to your div content
.col-md-5 { background-color: red; }
.col-md-7 { background-color: green; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<h5>Example 1:</h5>
<div class="container">
<div class="row">
<div class="col-md-5">Cost:</div>
<div class="col-md-7"></div>
</div>
<div class="row">
<div class="col-md-5">Total:</div>
<div class="col-md-7">{{ total }}</div>
</div>
</div>
<h5>Example 2:</h5>
<div class="container">
<div class="row">
<div class="col-md-5">Cost:</div>
<div class="col-md-7"> </div>
</div>
<div class="row">
<div class="col-md-5">Total:</div>
<div class="col-md-7">{{ total }}</div>
</div>
</div>
Use span if you want elements to be inline instead of div. Wrap your inline elements inside a div of complete length
<div class="col-md-12">
<span class="col-md-5">Cost:</span>
<span class="col-md-7">{{ cost }}</span>
</div>
<div class ="col-md-12">
<span class="col-md-5">Total:</span>
<span class="col-md-7">{{ total }}</span>
</div>
Demo : http://jsfiddle.net/HB7LU/11572/
P.S : change the value of cost and test it.

Resources