Navigation Issue angular and typescript - angularjs

I have an issue with my navigation bar. I used ngRoute from AngularJs and I can't understand why all the links work wrong at click.
Here my code:
app.ts file:
module AnimalPlanet {
export var app: angular.IModule;
app= angular.module("mainAnimalPlanet",["ngRoute"]);
app.config(['$routeProvider', ($routeProvider:ng.route.IRouteProvider, $locationProvider:angular.ILocationProvider) => {
$routeProvider.when('/', {
templateUrl: 'templates/main.html',
controller:"a"
})
.when('/pets', {
templateUrl: 'templates/pets.html',
controller:"MenuItemCtrl"
})
.when('/ldAdoption', {
templateUrl: 'templates/ldAdoption.html',
controller:"c"
})
.when('/111111', {
templateUrl: 'templates/contact.html',
controller:"d"
})
.when('/impressum', {
templateUrl: 'templates/impressum.html',
controller:"e"
})
.otherwise({
redirectTo: '/'
});
}]);
}
menuItem.ts file:
"use strict";
module AnimalPlanet {
export class MenuItemCtrl {
names: any[];
constructor(names) {
this.names = [{
name: "Main",
slug: "main",
active: true,
link: "/"
}, {
name: "Pets",
slug: "pets",
active: false,
link: "/pets"
}, {
name: "LDAdoption",
slug: "ldAdoption",
active: false,
link: "/ldAdoption"
}, {
name: "Contact",
slug: "contact",
active: false,
link: "/contact"
}, {
name: "Impressum",
slug: "impressum",
active: false,
link: "/impressum"
}];
}
}
angular.module('mainAnimalPlanet',['ngRoute']).controller("MenuItemCtrl", ["$scope", MenuItemCtrl]);
}
Please help me!!! Thank you!

Related

Monaco editor does not work in angular tab

I am using Monaco editor with angular 1.6, In my UI I have different tabs(as in [this][1] example) pointing to different html page.
[1]: https://www.w3schools.com/howto/howto_js_tabs.asp I am using Monaco editor, but the problem is it is getting applied(integrated) to the items(text/textbox) only the first tab , if I apply in in other tab other than the first it is not showing up there , this is the bit of my code just to get an idea.
angular.module('sample').config(['$routeProvider', function ($routeProvider) {
$routeProvider.when('/', {
templateUrl: '/',
controller: 'MainCtrl'
}).when('/sample1', {
templateUrl: '/sample1',
controller: 'sample1Ctrl'
}).when('/sample2', {
templateUrl: '/sample2',
controller: 'sample2Ctrl',
}).when('/sample3', {
templateUrl: '/sample3',
controller: 'sample3Ctrl'
}).when('/sample4', {
templateUrl: '/sample4',
controller: 'sample4Ctrl'
}).otherwise({
redirectTo: '/'
});
}]);
angular.module('sample').controller('TabCtrl', function ($scope) {
$scope.tabs = [
{
slug: 'sample1',
title: "Register sample1",
content: "sample1"
},{
slug: 'sample2',
title: "Register sample2",
content: 'sample2'
},
{
slug: 'sample3',
title: "Get sample3",
content: "sample3"
},
{
slug: 'sample4',
title: "Register sample4",
content: "sample4"
}
];
});
this is how I am using Monaco editor in the controller
$scope.experimentConfigEditor = monaco.editor.create(document.getElementById('experimentText'), {
value: '',
language: 'json',
minimap: {
enabled: false
}
});
$scope.newExperimentConfigEditor = monaco.editor.create(document.getElementById('newExperimentText'), {
value: '',
language: 'json',
minimap: {
enabled: false
}
});
$scope.getConfigFromDatalensTextEditor = monaco.editor.create(document.getElementById('getText'), {
value: '',
language: 'json',
minimap: {
enabled: false
}
});
and this is the sample html file
<div id="experimentText" name="experimentText" style="width:600px;height:200px;border:1px solid grey" ng-show="experimentText" ng-model="formData. experimentText"></div>
So If I use the controller with Monaco in the first tab then only Monaco is getting applied otherwise it's not working the html elements are coming as an simple elements without Monaco editor in UI.

Load resources in angular with oclazyload and webpack

I have a modular app who have multiple vendor plugins and I need to load only necessary in every view.
This is my routes:
(function() {
'use strict';
angular.module('app.empresas').config(config);
function config($stateProvider, $ocLazyLoadProvider) {
$stateProvider
.state('app.empresas', {
url: '/empresas?Filter',
views: {
'main#': {
template: require('./empresas/empresas.html'),
controller: "AppController as App"
}
},
Params: {
title: 'Empresas',
bodyClass: '',
requiredLogin: true
}
})
.state('app.empresas.view', {
url: '/empresas/:ItemId',
views: {
'main#': {
template: require('./empresas.view/empresas.view.html'),
controller: "AppController as App"
}
},
Params: {
title: 'Empresa',
bodyClass: '',
requiredLogin: true
}
})
}
})();
I know how to include oclazyload resources without webpack, but now I need to include specific resources for every view. ¿How can do this?
I solved it using this snippet:
This is a sample of a state
.state('app.empresas.view', {
url: '/empresas/:ItemId',
views: {
'main#': {
templateUrl: '/app/main/apps/empresas/empresas.view/empresas.view.html',
controller: "AppController as App"
}
},
Params: {
title: 'Empresa',
bodyClass: '',
requiredLogin: true
},
resolve: ['$q', '$ocLazyLoad', function ($q, $ocLazyLoad) {
var deferred = $q.defer();
var mod = importAll(require.context('./empresas.view/', true, /\.*$/));
$ocLazyLoad.load({
name: 'app.empresas.view'
});
deferred.resolve(mod);
return deferred.promise;
}]
})
I use this function with require to load entire folder with oclazyload and compile with webpack in a bundle separate file:
function importAll (r) {r.keys().forEach(r);}
I can load css, html, js files in one view without require files one by one

How to resolve for angular ui-route

Here is my angularjs code. I have created different routes but i am unable to resolve my contract.dashboard route. If i remove the route object, it works fine but when i tried to reslove something from my service, it dose not work.
(function() {
'use strict';
angular
.module('app.contracts')
.run(appRun);
var _base = {
// Contract Base Contractor
contract: {
controllerAs: 'c',
controller: ['$scope', '$state', 'ContractModel', function($scope, $state, ContractModel){
'ngInject';
var that = this;
$scope.$watch(function(){ return $state.current.data.mode; }, function() { that.mode = $state.current.data.mode; });
that.contract = new ContractModel();
}]
}
};
/* #ngInject */
function appRun(routerHelper) {
routerHelper.configureStates(getStates());
}
function getStates() {
return [
{
state: 'contract',
config: angular.extend({
abstract: true,
template: '<contract-manager><ui-view/></<contract-manager>',
url: '/contract'
}, _base.contract)
},
{
state: 'contract.new',
config: angular.extend({
url: '/new',
template: '<contract-editor mode="c.mode" contract="c.contract"></<contract-editor>',
title: 'Contract Editor',
data: {
mode: 'new'
}
}, _base.contract)
},
{
state: 'contract.dashboard',
config: angular.extend({
url: '',
template: '<contract-dashboard></contract-dashboard>',
title: 'Contract Dashboard',
data: {
mode:'dashboard'
},
resolve: {
stubs: function(stubs){
return stubs.service.registerGetCustomers();
}
}
}, _base.contract)
}
];
}
})();

Angular2 Nested Routing parent to child ES5 not working

Current working on angular2 beta version 6, in this nested routing like parent to child using (EX: /plan/...) future is not working on es5 JavaScript development, but in type script development it's working perfectly
Throwing error: EXCEPTION: Link "["Plan"]" does not resolve to a terminal instruction.
App.js code
var Tabs = [],viewId;
app.AppComponent =
ng.core.Component({
selector: 'app',
template: '<router-outlet></router-outlet>',
directives: [ng.router.ROUTER_DIRECTIVES],
providers: [ng.http.HTTP_PROVIDERS]
})
.Class({
constructor: [ng.router.Router, function(router) {
console.log("1");
router.config([
{ path: '/', redirectTo: ['Home'] },
{ path: '/home', component: app.HomeComponent, name: 'Home' },
{ path: '/plan/...', component: app.planComponent, name: 'Plan' }
]);
}]
});
document.addEventListener('DOMContentLoaded', function() {
ng.platform.browser.bootstrap( app.AppComponent,[ng.router.ROUTER_PROVIDERS]);
});
Plan.js code
app.planComponent =
ng.core.Component({
selector: 'plan-view',
templateUrl: './assets/src/plan/view/plan.html',
directives: [ ng.router.RouterLink, ng.router.ROUTER_DIRECTIVES],
})
.Class({
constructor:[ng.router.Router, function(router){
console.log("2");
router.config([
{ path: '/', redirectTo: ['PlanInfo'] },
{ path: '/planInfo', component: app.planInfoComponent, name: 'PlanInfo', useAsDefault: true }/*,
{ path: '/coverage', component: app.CoverageComponent, name: 'Coverage' },
{ path: '/nonelective', component: app.nonElectiveComponent, name: 'NonElective' },
{ path: '/loans', component: app.loansComponent, name: 'Loans' },
{ path: '/enrollment', component: app.enrollmentComponent, name: 'Enrollment' }*/
]);
}]
});
I think that you should use the ng.router.RouteConfig decorator instead of the router itself. Like this, you will have the same configuration as with TypeScript.
Here is the way to do:
ng.router
.RouteConfig([
{ path: '/', redirectTo: ['Home'] },
{ path: '/home', component: app.HomeComponent, name: 'Home' },
{ path: '/plan/...', component: app.planComponent, name: 'Plan' }
])(app.AppComponent);
(...)
ng.router
.RouteConfig([
{ path: '/', redirectTo: ['PlanInfo'] },
{ path: '/planInfo', component: app.planInfoComponent, name: 'PlanInfo', useAsDefault: true }/*,
{ path: '/coverage', component: app.CoverageComponent, name: 'Coverage' },
{ path: '/nonelective', component: app.nonElectiveComponent, name: 'NonElective' },
{ path: '/loans', component: app.loansComponent, name: 'Loans' },
{ path: '/enrollment', component: app.enrollmentComponent, name: 'Enrollment' }*/
])(app.planComponent);
As a reference, you could have a look at this plunkr: https://plnkr.co/edit/w61Ecbmuj7EfDnsYEHOS?p=info.

ui-router nested states over two levels

I'm trying to nest states over two levels but i get the following error:
Error: Could not resolve 'purchases.inventory.create-move' from state 'purchases.inventory'
Here are the first and second level routes:
(function () {
'use strict';
angular.module( 'app.purchases' )
// Collect the ui-route states
.constant( 'states', getRouteStates() )
// Configure the ui-route states and state resolvers
.config( [ '$stateProvider', '$urlRouterProvider', 'states', stateConfigurator ] );
function stateConfigurator( $stateProvider, $urlRouterProvider, states ) {
states.forEach( function ( state ) {
$stateProvider.state( state.name, state.config );
} );
$urlRouterProvider.otherwise( "/" );
}
// Define the ui-route states
function getRouteStates() {
return [
{
name: 'purchases',
config: {
url: '/compras',
views: {
'content-body': {
templateUrl: './modules/purchases/purchases-dashboard.view.html',
controller: 'PurchasesDashboardController',
controllerAs: 'vm'
}
},
ncyBreadcrumb: {
label: 'Compras'
}
}
},
{
name: 'purchases.inventory',
config: {
url: '/movimientos',
views: {
'panel-body': {
templateUrl: './modules/purchases/inventory/inventory-dashboard-options.view.html',
controller: 'InventoryDashboardController',
controllerAs: 'vm'
}
},
ncyBreadcrumb: {
label: 'Inventario'
}
}
},
{
name: 'purchases.products',
config: {
url: '/productos',
views: {
'panel-body': {
templateUrl: './modules/purchases/products/products-dashboard-options.view.html',
controller: 'ProductsDashboardController',
controllerAs: 'vm'
}
},
ncyBreadcrumb: {
label: 'Productos'
}
}
},
{
name: 'purchases.suppliers',
config: {
url: '/proveedores',
views: {
'content-body': {
templateUrl: './modules/purchases/suppliers/suppliers-dashboard-options.view.html',
controller: 'SuppliersDashboardController',
controllerAs: 'vm'
}
},
ncyBreadcrumb: {
label: 'Proveedores'
}
}
}
];
}
})();
Here are the third level routes (These aren't working):
(function () {
'use strict';
angular.module( 'app.purchases.inventory' )
// Collect the ui-route states
.constant( 'states', getRouteStates() )
// Configure the ui-route states and state resolvers
.config( [ '$stateProvider', '$urlRouterProvider', 'states', stateConfigurator ] );
function stateConfigurator( $stateProvider, $urlRouterProvider, states ) {
states.forEach( function ( state ) {
$stateProvider.state( state.name, state.config );
} );
$urlRouterProvider.otherwise( '/' );
}
// Define the ui-route states
function getRouteStates() {
return [
{
name: 'pruchases.inventory.create-move',
config: {
url: '/nuevo-movimiento',
views: {
'panel-body#': {
templateUrl: './modules/purchases/inventory/create-move/create-move.view.html',
controller: 'CreateMoveController',
controllerAs: 'vm'
}
},
ncyBreadcrumb: {
label: 'Nuevo Movimiento'
}
}
},
{
name: 'pruchases.inventory.list-moves',
config: {
url: '/movimientos',
views: {
'panel-body#': {
templateUrl: './modules/purchases/inventory/read-moves/list-moves.view.html',
controller: 'ReadMovesController',
controllerAs: 'vm'
}
},
ncyBreadcrumb: {
label: 'Lista de Movimientos'
}
}
},
{
name: 'pruchases.inventory.detail-move',
config: {
url: '/movimientos/:move_id/:move_date',
views: {
'panel-body#': {
templateUrl: './modules/purchases/inventory/read-moves/detail-move.view.html',
controller: 'ReadMovesController',
controllerAs: 'vm'
}
},
ncyBreadcrumb: {
label: 'Detalle'
}
}
},
{
name: 'pruchases.inventory.update-move',
config: {
url: '/movimientos/:move_id/:move_date/actualizar',
views: {
'panel-body#': {
templateUrl: './modules/purchases/inventory/update-move/update-move.view.html',
controller: 'UpdateMoveController',
controllerAs: 'vm'
}
},
ncyBreadcrumb: {
label: 'Actualizacion'
}
}
}
];
}
})();
In the template what i do is:
<a ui-sref="pruchases.inventory.create-move">Create Move</a>
Is that ui-router doesn't support over two level nested routes?
I just mispelled the state name, here are the corrected states:
function getRouteStates() {
return [
{
name: 'purchases.inventory.create-move',
config: {
url: '/nuevo-movimiento',
views: {
'panel-body#': {
templateUrl: './modules/purchases/inventory/create-move/create-move.view.html',
controller: 'CreateMoveController',
controllerAs: 'vm'
}
},
ncyBreadcrumb: {
label: 'Nuevo Movimiento'
}
}
},
{
name: 'purchases.inventory.list-moves',
config: {
url: '/movimientos',
views: {
'panel-body#': {
templateUrl: './modules/purchases/inventory/read-moves/list-moves.view.html',
controller: 'ReadMovesController',
controllerAs: 'vm'
}
},
ncyBreadcrumb: {
label: 'Lista de Movimientos'
}
}
},
{
name: 'purchases.inventory.detail-move',
config: {
url: '/movimientos/:move_id/:move_date',
views: {
'panel-body#': {
templateUrl: './modules/purchases/inventory/read-moves/detail-move.view.html',
controller: 'ReadMovesController',
controllerAs: 'vm'
}
},
ncyBreadcrumb: {
label: 'Detalle'
}
}
},
{
name: 'purchases.inventory.update-move',
config: {
url: '/movimientos/:move_id/:move_date/actualizar',
views: {
'panel-body#': {
templateUrl: './modules/purchases/inventory/update-move/update-move.view.html',
controller: 'UpdateMoveController',
controllerAs: 'vm'
}
},
ncyBreadcrumb: {
label: 'Actualizacion'
}
}
}
];
}

Resources