I'm trying to create a navigation bar, this is how my html code looks like.....
<div class="container">
<div class="row">
<div class="navbar navbar-default">
<div class="navbar-header">
<ul class="nav navbar-nav">
<li><span class="navbar-brand">Registration</span></li>
</ul>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>Courses</li>
<li>Instructors</li>
</ul>
</div>
</div>
<div ng-view></div>
</div>
</div>
I have put 'ng-app' tag in my Layout page............. My issue is when i click these two navigation buttons, it will give me an error page saying page not found(404 error code)......... this is how my module looks like.............
var registrationModule = angular.module("registrationModule", [])
.config(function ($routeProvider, $locationProvider) {
$routeProvider.when('/Courses', { templateUrl: '/Templates/Course.cshtml', controller: 'CoursesController' });
$routeProvider.when('/Instructors', { templateUrl: '/Templates/Instructor.cshtml', controller: 'InstructorsController' });
$locationProvider.html5Mode(true);
})
;
These are the two templates i have created..........
1. Course.cshtml:
<div class="row">
<h2>Course</h2>
<div class="span10">
<table class="table table-condensed table-hover">
<tr>
<th>Course</th>
<th>Course Name</th>
<th>Instructor</th>
</tr>
<tr ng-repeat="course in courses">
<td>{{course.number}}</td>
<td>{{course.name}}</td>
<td>{{course.instructor}}</td>
</tr>
</table>
</div>
</div>
2.Instructor.cshtml:
<div class="row">
<h2>Instructor</h2>
<div class="span10">
<table class="table table-condensed table-hover">
<tr>
<th>Room Number</th>
<th>Instructor's Name</th>
<th>Email</th>
</tr>
<tr ng-repeat="instructor in instructors">
<td>{{instructor.roomNumber}}</td>
<td>{{instructor.name}}</td>
<td>{{instructor.email}}</td>
</tr>
</table>
</div>
</div>
You can't access cshtml file through url because they are nothing but analysed C# razor engine, I'd prefer you to load those .cshtml file from controller action. Instead of directive path of cshtml load it using asp.net mvc controller action.
CODE
var registrationModule = angular.module("registrationModule", [])
.config(function($routeProvider, $locationProvider) {
$routeProvider.when('/Courses', {
//templates controller Course action will return Course.cshtml
templateUrl: '/Templates/Course',
controller: 'CoursesController'
});
$routeProvider.when('/Instructors', {
//templates controller Instructor action will return Instructor.cshtml
templateUrl: '/Templates/Instructor',
controller: 'InstructorsController'
});
$locationProvider.html5Mode(true);
});
Related
I am building a pagination table and i am using routeprovider. So the flow is on the homepage user is presented with a carousel when he clicks the text on carousel he is directed to a new html page called queryBoard, where there is a form to submit some details, it then fetches the data from back and displays in tabular format but when user is redirected to queryBoard page i keep getting error
Unknown provider: ngTableParamsProvider
I have included 'ngTable' in my module.
Main.js
angular.module('ui.bootstrap.demo', ['pageslide-directive', 'ngAnimate', 'ui.bootstrap', 'ngTable', 'ngRoute']);
index.html
<html ng-app="ui.bootstrap.demo">
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular-animate.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular-route.js"></script>
<script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-1.3.3.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://rawgit.com/esvit/ng-table/master/dist/ng-table.min.css">
<script src="https://rawgit.com/esvit/ng-table/master/dist/ng-table.min.js"></script>
<script src="resources/js/main.js"></script>
<script src="resources/js/CarouselController.js"></script>
<script src="resources/js/dashboardrouter.js"></script>
<script src="resources/js/TypeAheadController.js"></script>
<script src="resources/js/angular-pageslide-directive.js"></script>
</head>
<body>
<h2>AngularJS Sample Application</h2>
<div ng-view></div>
</body>
</html>
welcome.html [user is presented with carousel and on click he is routed to a new page]
<h1 class="text-center text-primary centered">Welcome to ananta-gs dashboard</h1>
<div>
<uib-carousel active="active" interval="myInterval" no-wrap="noWrapSlides" style="height: 305px; width: 450px; margin:auto">
<uib-slide ng-repeat="slide in slides track by slide.id" index="slide.id">
<img ng-src="/resources/images/cloud-home.jpg" style="height:305px; margin:auto;">
<div class="carousel-caption">
<a ng-click='sendEnvName(slide.text)'>
<h3 class="carousel-caption text-primary center-block">
{{slide.text}}</h3>
</a>
</div>
</uib-slide>
</uib-carousel>
There are exceptions during app initialization, click here to see details
</div>
Carousel.js [relevant part]
$scope.sendEnvName = function (gridName) {
alert(gridName)
$location.path("/queryBoard/"+gridName);
}
dashboardrouter.js
angular.module('ui.bootstrap.demo').config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/welcome', {
templateUrl: 'welcome.html',
controller: 'CarouselDemoCtrl'
}).
when('/queryBoard/:gridName', {
templateUrl: 'query/queryboard.html',
controller: 'documentNameTypeAheadController',
}).
otherwise({
redirectTo: '/welcome'
});
}]);
TypeAheadCOntroller.js
angular.module('ui.bootstrap.demo').controller('documentNameTypeAheadController', function ($scope, $http, $filter, ngTableParams,
$uibModal, $timeout, $log, $window,
$routeParams) {
alert($routeParams.gridName);
});
QueryBoard.html
<title>Query Board</title>
<script type="text/css">
.app-modal-window .modal-dialog {
width: 500px;
}
</script>
<body>
<script type="text/html">
<ul class="dropdown-menu" role="listbox">
<li ng-repeat="match in matches track by $index"/>
</ul>
</script>
<div class='container-fluid typeahead-demo' ng-controller="documentNameTypeAheadController">
<h1>Query Board</h1>
<form class="form-inline" role="form" ng-submit="submit()">
<div class="form-group">
<input type="text" placeholder="type-name" ng-model="selectedDocumentTypeName"
uib-typeahead="state for state in states | filter:$viewValue | limitTo:8"
class="form-control">
</div>
<div class="form-group col-md-offset-1">
<input type="text" placeholder="search criteria" class="form-control" ng-model="queryCriteria">
</div>
<button type="submit" class="btn btn-default col-md-offset-1">Submit</button>
<div>
<table ng-table="tableParams" show-filter="true" class="table">
<thead>
<tr>
<th ng-repeat="headerName in headerNames"
class="text-center sortable">
{{headerName}}
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="user in paginatedDetailedDataType">
<td ng-repeat="headerName in headerNames">
<div class="animate-switch" ng-if="headerName == spaceIdFieldName">
{{user[headerName]}} </div>
<div class="animate-switch" ng-if="headerName != spaceIdFieldName">{{user[headerName]}}</div>
</td>
<script type="text/ng-template" id="DetailedQueryView.html">
<div class="modal-header">
<h3>Detailed Query view for {{detailedTypeName}} spaceId {{detailedSpaceId}}</h3>
</div>
<div class="modal-body">
<table ng-table="tableParams" show-filter="true" class="table">
<thead>
<tr>
<th>Key</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="property in detailedObjectProperties">
<td>{{ property.key }}</td>
<td>
<div ng-show="property.disabled">{{property.value}}</div>
<div ng-hide="property.disabled"><input type="text" ng-model="property.value"/>
</div>
</tr>
</table>
</div>
<div class="modal-footer">
<button class="btn btn-primary" ng-hide="updateEnabled" ng-click="edit()">Edit</button>
<button class="btn btn-primary" ng-show="updateEnabled" ng-click="save()">Save</button>
<button class="btn btn-warning" ng-click="cancel()">Cancel</button>
</div>
</script>
</tr>
</tbody>
</table>
</div>
</form>
</div>
</body>
I tried including the ngTable in TypeAheadController also but doesnot works, Can you please guide me where am i going wrong
Using Aurelia, I have the following model:
export class Services {
heading = 'Services';
services = [
{ 'name': 'Test Service', 'instances': [{'uri': 'test_uri'}]},
{ 'name': 'Another Service', 'instances': [{'uri': 'other_uri'}, {uri: 'backup_uri'}]}
];
}
and the following view:
<template>
<require from="bootstrap/css/bootstrap.css"></require>
<div class="container">
<div class="row">
<div class="col-md-12">
<h2>${heading}</h2>
</div>
</div>
<div class="row" repeat.for="service of services">
<div class="panel panel-default">
<div class="panel-heading">${service.name}</div>
<table class="table">
<thead>
<tr>
<th>URI</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<div repeat.for="instance of service.instances">
<tr>
<td>${instance.uri}</td>
<td>Running</td>
</tr>
</div>
</tbody>
</table>
</div>
</div>
</div>
</template>
The outer repeat.for seems to work correctly and ${service.name} is replaced with the .name property from the model. However, ${instance.uri} does not give any output. If I replace ${instance.uri} with ${service.instances[0].uri} I do get the output expected.
In addition, I expect the second repeat of service of services to generate two lines in the table body, but it generates only one.
I've tried replacing <div repeat.for="instance of service.instances"> with <div repeat.for="instance of $parent.instances"> with the same unsatisfactory result.
What do I need to change to ensure that the inner repeat works correctly?
Browsers do not allow divs in tables.
change this:
<tbody>
<div repeat.for="instance of service.instances">
<tr>
<td>${instance.uri}</td>
<td>Running</td>
</tr>
</div>
</tbody>
to this:
<tbody>
<tr repeat.for="instance of service.instances">
<td>${instance.uri}</td>
<td>Running</td>
</tr>
</tbody>
I have Home Team and away Team Scorer in my HTML and i want to sort each Goal Scorer in Minutes (Ascending). Here is the HTML Code:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Sort</title>
<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.css">
<script src="angular/angular.min.js"></script>
<script>
(function(angular) {
'use strict';
angular.module('orderByScore', [])
.controller('ScoreController', ['$scope', function($scope) {
$scope.goals =
[{scorer:'Glen', mins:'40"', type:'Own Goal', min:40},
{scorer:'Beckham', mins:'20"', type:'Goal', min:20},
{scorer:'Ronaldo', mins:'70"', type:'Own Goal', min:70}];
}]);
})(window.angular);
</script>
<script>
(function(angular) {
'use strict';
angular.module('orderByScore', [])
.controller('ScoreControllerX', ['$scope', function($scope) {
$scope.goalsx =
[{scorer:'Glen', mins:'4"', type:'Goal', min:4},
{scorer:'Glen', mins:'75"', type:'Goal', min:75},
{scorer:'David', mins:'30"', type:'Own Goal', min:30}];
}]);
})(window.angular);
</script>
</head>
<body ng-app="orderByScore">
<div ng-controller="ScoreController">
<div class="home-team col-md-6">
<table class="goalx">
<tr style="display: none">
<th>Scorer</th>
<th>Minute</th>
<th>Type</th>
<th>Min</th>
</tr>
<tr ng-repeat="goalx in goalsx | orderBy:'+min'">
<td>{{goal.scorer}}</td>
<td>{{goal.mins}}</td>
<td>{{goal.type}}</td>
<td style="display: none">{{goal.min}}</td>
</tr>
</table>
</div>
<div class="away-team col-md-6">
<table class="goal">
<tr style="display: none">
<th>Scorer</th>
<th>Minute</th>
<th>Type</th>
<th>Min</th>
</tr>
<tr ng-repeat="goal in goals | orderBy:'+min'">
<td>{{goal.scorer}}</td>
<td>{{goal.mins}}</td>
<td>{{goal.type}}</td>
<td style="display: none">{{goal.min}}</td>
</tr>
</table>
</div>
</div>
</body>
</html>
If away team is working, home team is not displaying. if home team display the away team is dissappear. I want the home and away team scorer display. Please Help to make it work.
You will have to use ng-repeat with filters. In your case, you will have to use orderby filter.
<ul>
<li ng-repeat="goal in goalsx | orderBy:'goal.mins'">{{goal.scorer}}</li>
</ul>
Hope this helps.
replace goal with goalx in ng-repeat="goalx in goalsx | orderBy:'+min' like {{goalx.scorer}}
In home team's case you used "ng-repeat = goalx in goalsx" but inside the div everywhere you used "goal.scorer","goal.miins", etc. All you have to do is replace the ng-repeat as "ng-repeat = goal in goalsx".
<div class="home-team col-md-6">
<table class="goalx">
<tr style="display: none">
<th>Scorer</th>
<th>Minute</th>
<th>Type</th>
<th>Min</th>
</tr>
<tr ng-repeat="goal in goalsx | orderBy:'+min'"> // use 'goal in goalsx' here
<td>{{goal.scorer}}</td>
<td>{{goal.mins}}</td>
<td>{{goal.type}}</td>
<td style="display: none">{{goal.min}}</td>
</tr>
</table>
</div>
<div class="away-team col-md-6">
<table class="goal">
<tr style="display: none">
<th>Scorer</th>
<th>Minute</th>
<th>Type</th>
<th>Min</th>
</tr>
<tr ng-repeat="goal in goals | orderBy:'+min'">
<td>{{goal.scorer}}</td>
<td>{{goal.mins}}</td>
<td>{{goal.type}}</td>
<td style="display: none">{{goal.min}}</td>
</tr>
</table>
</div>
I have one table which will fill with the JSON data. After the filling table, If some one wants to modify any row then it will pop-up window, where you can modify.
What I am doing:
I made two controller, I want to pass the ng-model value from one controller to other controller which is controller for window.
Please tell me how to connect these two controller.
Please see the running example,
http://plnkr.co/edit/6lRT1B1sYcEx0lVCJiZZ?p=preview
index.html
<!DOCTYPE html>
<html>
<head>
<title>ToDo API Client Demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.js"></script>
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet">
<script src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="navbar">
<div class="navbar-inner">
<a class="brand" href="#">ToDo API Client Demo</a>
</div>
</div>
<div ng-app="myApp" ng-controller="tasksCtrl">
<table class="table table-striped">
<tr><td style="width: 1px;"></td><td><b>Task</b></td><td><b>Options</b></td></tr>
<tr ng-repeat="task in tasks">
<td>{{task.title}}</td>
<td>{{task.description}}</td>
<td> <a class="btn" data-toggle="modal" data-target="#modal" ng-click="editTask(task)">Edit</a></td>
</tr>
</table>
</div>
<div id="modal" role="dialog" class="modal hide fade">
<div ng-controller="TaskController">
<div class="modal-header">
Task Dialog
</div>
<div class="modal-body">
<label for="txtName"></label>
<input type="text" ng-model="task.title" />
<input type="text" ng-model="task.description" />
</div>
<div class="modal-footer">
<button class="btn btn-primary" ng-click="saveTask()" data-dismiss="modal">OK</button>
</div>
</div>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('tasksCtrl', function($scope, $http) {
$http.get("data.json")
//$http.get("/todo/api/v1.0/tasks")
.success(function(response) {
console.log(response.tasks)
$scope.tasks = response.tasks;
});
});
app.controller('TaskController', function($scope, $rootScope){
$scope.editTask=function(task){
$rootScope.task=task;
}
});
</script>
</body>
</html>
First, place your ng-app="myApp" and ng-controller="tasksCtrl" to the body element.
E.g.
<body ng-app="myApp" ng-controller="tasksCtrl">
Then, move the
$scope.editTask=function(task) {
$scope.task = task;
};
To the tasksCtrl. The TaskController is no longer needed. You can remove it.
Since, it only use one controller you can use $scope instead of $rootScope.
Here's the Plunkr.
Hope it helps.
What you are trying to do would create a tight coupling between controllers but from what I see in the plunkr you would be better off with using angular-ui modal and just instantiate the modal window from code.
There are few mistakes that you did
First one that you modal html code is not inside ng-app
and you can use is Parent Child Concept of Angular ,In which you have no need to use $rootScope
Pluncker having complete solution of your problem:http://plnkr.co/edit/lRNJjM3aUIqQWFfE39yo?p=preview
Html:
<div ng-app="myApp" ng-controller="tasksCtrl">
<table class="table table-striped">
<tr><td style="width: 1px;"></td><td><b>Task</b></td><td><b>Options</b></td></tr>
<tr ng-repeat="task in tasks">
<td>{{task.title}}</td>
<td>{{task.description}}</td>
<td> <a class="btn" data-toggle="modal" data-target="#modal" ng-click="editTask(task)">Edit</a></td>
</tr>
</table>
<div id="modal" role="dialog" class="modal hide fade">
<div ng-controller="TaskController">
<div class="modal-header">
Task Dialog
</div>
<div class="modal-body">
<label for="txtName"></label>
<input type="text" ng-model="Edittask.title" />
<input type="text" ng-model="Edittask.description" />
</div>
<div class="modal-footer">
<button class="btn btn-primary" ng-click="saveTask()" data-dismiss="modal">OK</button>
</div>
</div>
</div>
</div>
Controller:
var app = angular.module('myApp', []);
app.controller('tasksCtrl', function($scope, $http) {
$http.get("data.json")
//$http.get("/todo/api/v1.0/tasks")
.success(function(response) {
console.log(response.tasks)
$scope.tasks = response.tasks;
});
$scope.editTask=function(task){
$scope.selectedTask=task;
}
});
app.controller('TaskController', function($scope, $rootScope){
$scope.Edittask={};
$scope.Edittask.title="";
$scope.Edittask.description="";
$scope.saveTask=function(){
console.log('called');
$scope.selectedTask.title=$scope.Edittask.title;
$scope.selectedTask.description=$scope.Edittask.description;
}
});
If you need to access any methods in other controller and pass the data you could do like this,
angular.element(document.getElementById('OtherControllersId')).scope().methodInOtherController(data);
I am using angularjs in my application. I have a problem with this code, this code generate data first time. But when I come back to that page from other location it give only expression written in jsp page
Below is my app.js
var app = angular.module("myModule",[]);
app.controller(
"ReportController",
function ($scope,$http) {
$http({
method: 'POST',
url: 'mypage_body.do',
data: 'action=fetchdata',
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
})
.success(function(response) {
$scope.questions = response;
});
}
);
angular.element(document).ready(function (){
angular.bootstrap(document,['myModule']);
});
It gives expression when I reload the page from other location
like this
{{question.title}}
{{cell.f}}{{cell.f}}
{{row.h}} {{row.v}} {{row.v}}
I analyzed that page is not loading again. Means document.ready is not calling again on that page. Could anyone please help how to call again the module written in app.js without using document.ready.
Any help would be appreciated.
Thanks in advance.
<script type="text/javascript" src="/campustoolshighered/css/js/angular-1.2.26.min.js"></script>
<script type="text/javascript" src="/campustoolshighered/css/js/adhocreport/app.js"></script>
<script type="text/javascript" src="/campustoolshighered/css/uiframework/js/bootstrap.js"></script>
<div ng-controller="ReportController">
<div class="row" ng-repeat="question in questions">
<div class="col-md-12">
<div class="module">
<div class="heading">
<h2>{{question.title}}</h2>
<div class="module-options">
<span tabindex="3" class="icon-settings pop" title="Edit" data-toggle="tooltip" data-popoverid="#icon-setting"><span class="sr-only">Widget settings</span></span>
</div>
</div>
<div class="module-content" >
<div class="row">
<div class="col-md-12">
<div class="table-wrap">
<table class="table table-striped">
<thead>
<tr>
<th scope="col" role="columnheader" ng-repeat="header in question.dataTable.cols" >{{header.label}}</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="row in question.dataTable.rows">
<td ng-repeat="cell in row.cells"><a ng-if="cell.link" href="{{cell.link}}" tabindex="3">{{cell.f}}</a><span ng-if="!cell.link">{{cell.f}}</span></td>
</tr>
</tbody>
</table>
</div>
<ul ng-show="question.aggregateTable">
<li ng-repeat="row in question.aggregateTable.rows">
<strong>{{row.h}} </strong>
<a ng-if="row.link" href="{{row.link}}" tabindex="3">{{row.v}}</a>
<span ng-if="!row.link">{{row.v}}</span>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
And if I do not bootstrap my code manually on document.ready page does not load angular js not even first time.