angular-ui-router v 0.4.2 with Angular 1.6.1 - angularjs

i am basically trying to make a simple routing:
where i have defined the following in app.js
(function () {
"use strict";
var app = angular.module("productManagment", ["common.services", "ui.router", "productResourceMock"]);
app.config(["$stateProvider","$urlRouterProvider","$locationProvider",
function ($stateProvider,$urlRouterProvider ,$locationProvider) {
$locationProvider.hashPrefix('');
$urlRouterProvider.otherwise('/products');
$stateProvider
.state('/products',
{
url: '/products',
templateUrl: 'app/products/productsView.html',
controller: "ProductListCtrl as vm"
});
}
]);
}());
i am using angular js 1.6.1 and angular-ui-router v 0.4.2 .
my index html is as follows:
<!DOCTYPE html>
<html>
<head>
<link href="css/bootstrap.css" rel="stylesheet"/>
<link href="css/app.css" rel="stylesheet" />
<!--Library scripts here-->
<script src="js/angular.js"></script>
<script src="js/angular-resource.js"></script>
<script src="js/angular-mocks.js"></script>
<script src="js/angular-ui-router.js"></script>
<script src="app/app.js"></script>
<script src="common/services/common.services.js"></script>
<script src="common/services/productResource.js"></script>
<script src="common/services/productResourceMock.js"></script>
<script src="app/products/productListCtrl.js"></script>
<meta charset="utf-8" />
</head>
<body ng-app="productManagment">
<div ui-view></div>
</body>
</html>
while the product list view is :
<div class="panel panel-primary">
<div class="panel-heading" style="font-size: large"> Product List</div>
<div class="panel-body">
<table class="table">
<thead>
<tr>
<td>
<button class="btn btn-primary" type="button"
ng-click="vm.toggleImage()">
{{vm.showImage ? "Hide" : "Show"}} Image
</button>
</td>
<td>Product</td>
<td>Code</td>
<td>Availability</td>
<td>Price</td>
</tr>
</thead>
<tbody>
<tr ng-repeat="product in vm.products">
<td>
<img ng-if="vm.showImage" ng-src="{{product.imageUrl}}"
style="width: 50px; margin: 2px"
title="{{product.productName}}" />
</td>
<td>{{product.productName}}</td>
<td>{{product.productCode}}</td>
<td>{{product.releaseDate}}</td>
<td>{{product.price | currency}}</td>
</tr>
</tbody>
</table>
</div>
</div>
when i try to run the application, it should be routed to the "/products" along with its template, but i got the below error from the developer tools of chrome:
Error: [$compile:tpload] Failed to load template: app/products/productsView.html (HTTP status: undefined undefined)
http://errors.angularjs.org/1.6.1/$compile/tpload?p0=app%2Fproducts%2FproductsView.html&p1=undefined&p2=undefined
at angular.js:68
at handleError (angular.js:19730)
at processQueue (angular.js:16648)
at angular.js:16692
at Scope.$eval (angular.js:17972)
at Scope.$digest (angular.js:17786)
at Scope.$apply (angular.js:18080)
at bootstrapApply (angular.js:1841)
at Object.invoke (angular.js:4842)
at doBootstrap (angular.js:1839)
the network tab shows:

After a long time of reproduction we were able reproduce were the problem was comming from. The ngMock configuration was blocking nearly any request fired by the client. We could solve the problem by allow AngularJS $httpBackend to GET sources in the following directoy app/views/* which results in the following pattern:
$httpBackend.whenGET(/^\/app/*/views\//).passThrough();

it turns out that the problem was caused because of the usage of MockE2E.
so if I make something like $httpBackend.whenGET("/app/products/productsView.html").passThrough();
it is not intercepted by the mock.

Related

asp.net mvc Angular js Datatable not working

I am new in angular js with datatable and i am getting when on page load, i am trying to add load datatable using angular js.
Error :
angular.js:138 Uncaught Error: [$injector:modulerr] Failed to instantiate module PMS due to:
Error: [$injector:modulerr] Failed to instantiate module angularMoment due to:
Error: [$injector:nomod] Module 'angularMoment' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
Detail Error
Error link
My Controller
var app = angular.module('PMS', ['angularMoment', 'ui.router', 'datatables'])
.filter('jsonDate', ['$filter', function($filter) {
return function(input, format) {
return (input) ? $filter('date')(parseInt(input.substr(6)), format) : '';
};
}]);
app.controller('SpaceController', function($scope, SpaceService) {
$scope.getAll = function() {
loader(true);
var getData = SpaceService.getAllData();
getData.then(function(response) {
if (response.data.success) {
$scope.listdt = response.data.data;
$scope.populateStatus();
loader(false);
} else {
errorAlert("Oops", response.data.message);
loader(false);
}
});
}
});
My Template
# {
Layout = null;
} <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<link href="~/Scripts/PMS_theme_js/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="~/Content/PMS_theme_css/css/style.css" rel="stylesheet">
</head>
<body ng-app="PMS" ng-controller="SpaceController">
<table datatable="ng" class="table display" id="TblID">
<thead>
<tr>
<th>ID</th>
<th>Key</th>
<th>Name</th>
<th>Description</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="d in listdt">
<td>{{d.SpaceID}}</td>
<td>{{d.SpaceKey}}</td>
<td>{{d.SpaceName}}</td>
<td>{{d.SpaceDesc}}</td>
<td> <span class="label label-table {{d.StatusKey == 'A' ? 'label-success' : 'label-red'}}">{{d.StatusName}}</span></td>
<td>
<a class="btn btn-primary btn-sm" ng-click="edit(d)"><i class="fa fa-pencil fa-lg"></i></a>
<a class="btn btn-danger btn-sm" ng-click="delete(d)"><i class="fa fa-trash fa-lg"></i></a>
</td>
</tr>
</tbody>
</table>
<script src="~/Scripts/PMS_theme_js/plugins/bower_components/jquery/dist/jquery.min.js"></script>
<script src="~/Scripts/PMS_theme_js/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="~/Scripts/angular.js"></script>
<script src="~/Scripts/angular-ui-router/release/angular-ui-router.min.js"></script>
<script src="~/Scripts/datatables/media/js/jquery.dataTables.js"></script>
<script src="~/Scripts/angular-datatables/dist/angular-datatables.js"></script>
<script src="~/Scripts/Angular/Module.js"></script>
</body>
</html>
Its working fine with Datatable,but when add datatable module its start getting error.Any reason where and what i am doing wrong with Angular js datatable.
An error you mentioned shows that you've not injected angularMoment correctly, refer to the documentation.
Ensure that you've included both moment.js and angular-moment.js in your application, which would look something like following in your case -
<script src="~/Scripts/moment/moment.js"></script>
<script src="~/Scripts/angular-moment/angular-moment.js"></script>

Angularjs is not displaying update data in table row, ng-repeat not working properly?

I'm trying to get Angular to display JSON data that I've managed to pull from a database and console also printing the data as expected, but table ng-repeat not displaying the data. even outside of the table data display properly. {{contactlists[0].name}}
<!DOCTYPE>
<html ng-app="nodeapp">
<head>
<title>AngularJs with Nodejs</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
</head>
<body>
<div class="container" ng-controller="nodeappctrl">
<div class="row">
<h1>Angularjs with api's</h1>
<p>{{contactlists[0].name}}</p>
</div>
</div>
<div class="container">
<div class="row">
<table class="table">
<thead>
<tr>
<th>SNo</th>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="contact in contactlists">
<td>{{$index}}</td>
<td>{{contact.name}}</td>
<td>{{contact.email}}</td>
<td>{{contact.number}}</td>
</tr>
</tbody>
</table>
</div>
</div>
<script src="https://code.angularjs.org/1.4.9/angular.min.js"></script>
<script type="text/javascript">
var nodeapp = angular.module('nodeapp', []);
nodeapp.controller('nodeappctrl', ['$scope', '$rootScope', '$log', '$http',
function($scope, $rootScope, $log, $http) {
var contactlist = {};
$http.get('/contactlist').success(function(data) {
$scope.contactlists = data;
//$scope.$apply();
console.log(JSON.stringify($scope.contactlists), null,2);
});
}
]);
</script>
<!--
// dummy data
var contactlists =[
{
name: 'Rajesh',
email: 'raj#g.com',
number: '11 - 111 - 11111'
}, {
name: 'Rajesh2',
email: 'raj2#g.com',
number: '22 - 222 - 222222'
}, {
name: 'Rajesh3',
email: 'raj3#g.com',
number: '33 - 333 - 333333'
}
]-->
</body>
</html>
</html>
Place ng-controller inside the <body> tag.
You used it in the <div> which is closed, so it's can't be available to the rest bottom of the code.
<body ng-controller="nodeappctrl">
//your code here..
</body>
The problem is here:
<div class="container" ng-controller="nodeappctrl">
The nodeappctrl controller should be applied to a tag that is a parent of where you're accessing its scope. As you can see, the table is a child of a sibling of the element the controller is bound to.
For example, move ng-controller="nodeappctrl" to the body tag.

NgMaps Center not working (Dynamic Point)

I'm using NgMaps in my Angular app
I'm trying to give the center point dynamically, but it's taking some other points which is not given by me:
HTML:
<ng-map zoom="5" center="{{center}}" style="height:600px">
</ng-map>
In controller:
$scope.center =[18.9750, 72.8258];
Here's the Plnkr Code:
http://plnkr.co/edit/hbNZdSKuUZqVSsJN7he3?p=preview
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<link rel="stylesheet" href="style.css">
<!-- JS -->
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js"></script>
<!-- load angular, ngRoute, ngAnimate -->
<script src="http://code.angularjs.org/1.4.7/angular.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular-route.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular-animate.js"></script>
<script src="http://rawgit.com/allenhwkim/angularjs-google-maps/master/build/scripts/ng-map.js"></script>
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
<ng-map zoom="8" center="{{center}}" style="height:600px">
<!-- <ng-map zoom="5" center="[20.1450107,77.8764691]" style="height:600px"> -->
<custom-control id="home" position="TOP_RIGHT" index="1000">
<div style="background-color: rgba(0,0,0,.5); color:#fff;width:200px;padding: 10px;" ng-if="customMarkers[0].clustors">
<table class="table table-condensed">
<thead>
<tr>
<th style="width: 50%">Priority</th>
<th style="width: 50%">Color</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="(key, value) in customMarkers[0].clustors">
<td>Priority {{$index}}</td>
<td class="{{clustorcolors[$index]}}"></td>
</tr>
</tbody>
</table>
</div>
</custom-control>
<div ng-repeat="(key, value) in customMarkers[0].clustors">
<div ng-repeat="point in value">
<custom-marker position="{{point.coordinate}}" on-mouseover="clustormouseover()" on-mouseout="clustormouseout()">
<div class="mappointer {{clustorcolors[$parent.$index]}}" ng-click="clickme(key,$index)">
<div class="infobox" id="clustor_{{$parent.$index}}_{{$index}}" ng-show="point.visibility">
BM_M_EXECTIVE : {{point.BM_M_EXECTIVE}},<br>
BM_PROFIT : {{point.BM_PROFIT}},<br>
BM_QUANTITY : {{point.BM_QUANTITY}},<br>
BM_NAME : {{point.BM_NAME}},<br>
BM_DISTRICT : {{point.BM_DISTRICT}},<br>
BM_TOTALPURCHASE : {{point.BM_TOTALPURCHASE}},<br>
</div>
</div>
</custom-marker>
</div>
</div>
</ng-map>
</body>
</html>
I don't know your case, but it seems working fine with me with the following example.
http://plnkr.co/edit/cec5b88WpZcoiSd1Mq28?p=preview
javascript
vm.center = "37.7699298, -122.4469157";
vm.setCenter = function() {
vm.center = "38.7699298, -123.4469157";
}
});
html
center: {{vm.center}}<br/>
<button ng-click="vm.setCenter()">Set Center to "38.7699298, -123.4469157"</button>
</div>
I had the same problem, because ngMap does not recognize the $interpolateProvider (according to #allenhwkim). Solution:
HTML:
<ng-map id="map" zoom="5" style="height:600px"></ng-map>
Javascript:
var that = this;
NgMap.getMap('map').then(function(map) {
that.map = map;
that.map.setCenter(new google.maps.LatLng(18.9750, 72.8258));
});
I hope, it helps someone. Thanks #allenhwkim for ngMap!

bootstrap tooltips not working when using it with angular ng-repeat and angular $interval together

Question: why isn't bootstrap like tooptips working when using it with angular ng-repeat and angular $interval
Behavior I'm seeing: when using bootstrap tooltips with angular ng-repeat and angular $interval, i am seeing the regular tooltips, not bootstrap like tooltips.
What i've tried:
if i use bootstrap tooltips with ng-repeat but disable the $interval, bootstrap tooltip works.
if i use bootstrap tooltips with $interval but remove ng-repeat, bootstrap tooltip works.
in the plunkr i've provided, lines 32, 33, you can disable/enable $interval for testing
http://plnkr.co/edit/6rUeJGsYfkgWMRrZoIYw?p=preview
<!DOCTYPE html>
<html ng-app="test">
<head>
<meta charset="UTF-8">
<title>angular-test</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" type="text/css" />
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('[data-toggle="tooltip"]').tooltip({container: 'body', placement: 'bottom'}); // initialize bootstrap tooltips
});
var app = angular.module("test", []);
app.controller("testCtrl", function($scope, $interval) {
var stats = [{
"name": "john",
"stat1": 3,
"stat2": 5
}];
var count = 0;
$scope.getTestInfo = function() {
$scope.count = count++;
$scope.stats = stats;
}
//$scope.getTestInfo(); // if dont use interval, bootstrap tooltip works
$interval(function(){$scope.getTestInfo();}, 1000); // if use interval, bootstrap tooltip doesnt work
});
</script>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-lg-4" ng-controller="testCtrl" ng-init="count=0">
<table id="table1" class="table table-hover table-condensed">
<thead>
<tr>
<th>column1</th>
<th>column2</th>
<th>column3</th>
</tr>
</thead>
<tbody class="bg-info">
<tr ng-repeat="stat in stats">
<td data-toggle="tooltip" title="{{count}}">{{stat.name}}</td>
<td data-toggle="tooltip" title="testcolumn2">{{stat.stat1 + count}}</td>
<td data-toggle="tooltip" title="testcolumn3">{{stat.stat2}}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>
You can use AngularUI tooltip which does all the work for you. Then your markup would look like this:
...
<tr ng-repeat="stat in stats" style="position: relative">
<td tooltip="{{count}}" tooltip-placement="bottom" tooltip-append-to-body="true">{{stat.name}}</td>
<td tooltip="testcolumn2" tooltip-placement="bottom" tooltip-append-to-body="true">{{stat.stat1 + count}}</td>
<td tooltip="testcolumn3" tooltip-placement="bottom" tooltip-append-to-body="true">{{stat.stat2}}</td>
</tr>
...
See updated plunker.

Uncaught object error on Chrome. Angularjs + ngResource

While using debug on Chrome, it keeps showing this error: uncaught object, on angular.js:36.
What am I doing wrong? :/
Thanks for any help :)
Module and Resource objects (services.js)
var services = angular.module('ngdemo.services', ['ngResource']);
services.factory('ProvidersFactory', function ($resource) {
return $resource('http://devfz.azurewebsites.net/api/providers/', {}, {
query: { method: 'GET', isArray: true },
})
});
Controller (controller.js)
var app = angular.module('ngdemo.controllers', []);
app.controller('ProviderListCtrl', ['$scope', 'ProvidersFactory', '$location',
function ($scope, ProvidersFactory, $location) {
$scope.providers = ProvidersFactory.query();
}]);
app.js
angular.module('ngdemo', ['ngdemo.filters', 'ngdemo.services', 'ngdemo.directives', 'ngdemo.controllers']).
config(['$routeProvider', function ($routeProvider) {
$routeProvider.when('/provider-list', { templateUrl: '/provider-list.html', controller: 'ProviderListCtrl' });
$routeProvider.otherwise({ redirectTo: '/provider-list' });
}]);
HTML
<!DOCTYPE html>
<html ng-app="ngdemo" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Providers</title>
<link href="Content/bootstrap.min.css" rel="stylesheet">
<script src="Scripts/Vendor/angular.min.js"></script>
<script src="Scripts/Vendor/angular-resource.js"></script>
<script src="controller.js"></script>
<script src="services.js"></script>
<script src="app.js"></script>
</head>
<body role="document" style="padding-top: 70px; padding-bottom: 30px">
<div class="container body-content" role="main">
<div ng-controller="ProviderListCtrl">
<h2>Providers</h2>
<hr>
<div style="width:60%">
<table class="table table-striped table-condensed">
<thead>
<tr>
<th style="min-width: 30px; width: 30px;">Id</th>
<th style="min-width: 100px;">Name</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="provider in providers">
<td valign="middle">Test: {{provider.Id}}</td>
<td valign="middle">Test: {{provider.Name}}</tdvalign>
<td valign="middle" align="right" width="40px"><a ng-click="" class="btn btn-small btn-primary">edit</a></td>
<td valign="middle" align="right" width="50px"><a ng-click="" class="btn btn-small btn-danger">delete</a></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>
Try to debug in Safari browser. For me it gets more information about this error. In my case I use angular-seed app and rename 'myApp' module to 'myNameOfAppApp'.
I received this error in Safari:
Error: [$injector:modulerr] Failed to instantiate module myApp due to:
[$injector:nomod] Module 'myApp' is not available! You either
misspelled the module name or forgot to load it. If registering a
module ensure that you specify the dependencies as the second
argument.
I try to find by 'mayApp' key word and after rename in index.html Error was fixed.
In order to use $routeProvider you need to include (and declare as a dependency) the ngRoute module.
See, this answer for more info.

Resources