I know that there are a lot of duplicates of this topic and I've found some articles which explain how to implement angularjs routeProvider with .cshtml, but it didn't help me. Here, in stackoverflow, there were some similar problems that I've looked at but it didn't help me either. Could you help me please.
Here is my angular module:
QuizApp.config(['$routeProvider',
function ($routeProvider) {
$routeProvider.
when('/index', {
templateUrl: '/home/index',
controller: 'QuizController' //new
}).
when('/quiz', {
templateUrl: '/home/quiz',
controller: 'QuizController' //new
}).
otherwise({
redirectTo: '/index'
});
}]);
If i join localhost:port/home/quiz - it works
If i join localhost:port/#/quiz - it is just show me default page (index).
ps. Guys, if you need some more information, just tell me please.
UPDATE 2.
Add a bit more code witch comments //new
Also I've found one defect that when i'm adding to my page:
<div ng-view></div>
Page just freeze, and I can't make anything on it.
Related
I've had a few errors trying to render single blog posts.
I tried using the page template with /post/{post_name} and I was getting this error:
warn Non-deterministic routing danger: Attempting to create page: "/blog/", but
page "/blog" already exists
This could lead to non-deterministic routing behavior
I tried again with /blog/{post_name}.
I now have both routes, which I'm not sure how to clean up; but more importantly, on those pages, nothing renders, even though there should be an h1 with it's innerhtml set to the node.title and likewise a div for the content.
I've uploaded my config and components to https://github.com/zackrosegithub/gatsby so you can have a look.
Not sure how to fix
I just want to see my content rendered on the screen.
Developer tools don't seem to help when there's no content rendered as I can't find anything to inspect to try to access it another way.
Thank you for your help
Your approach is partially correct. You are using a promise-based approach but when using then() you are already settling and partially resolving it so you don't need to use the callback of resolve(), which may be causing a duplication of the promise function so try removing it.
Additionally, you may want to use a more friendly approach using async/await functions. Something like:
exports.createPages = async ({ graphql, actions, reporter }) => {
const yourQuery= await graphql(
`
{
allWordpressPost {
edges{
node{
id
title
slug
excerpt
content
}
}
}
}
`
if (yourQuery.errors) {
reporter.panicOnBuild(`Error while running GraphQL query.`);
return;
}
const postTemplate = path.resolve("./src/templates/post.js")
_.each(yourQuery.data.allWordpressPost.edges, edge => {
createPage({
path: `/post/${edge.node.slug}/`,
component: slash(postTemplate),
context: edge.node,
})
})
})
// and so on for the rest of the queries
};
In addition, place a console.log(pageContext) in your postTemplate to get what's reaching that point and name the template as:
const Post = ({pageContext}) => {
console.log("your pageContext is", pageContext);
return <div>
<h1>
{pageContext.title}
</h1>
</div>
}
export default Post;
I want to refer to my earlier question: Meteor Dynamic Template not working
Using components in my app is working just fine on all other pages except on the root path:
FlowRouter.route('/', {
action() {
BlazeLayout.render('mainLayout', { content: 'home' });
},
});
The same components are working just fine here.
FlowRouter.route('/dashboard', {
action() {
BlazeLayout.render('mainLayout', { content: 'dashboard' });
},
});
I have imported the same components in both home.js and dashboard.js. The location of the files are the same and the imports are identical. My components work on all pages, but not if is root path.
Any help will be greatly appreciated. Thank you!
This was actually solved by a complete reboot. I tried restarting the application multiple times without luck.
I have a ASP.NET 4 Web Forms project written in C#. I would like to add Angular 2. I've seen a lot of examples on the web using ASP.NET 5 but I can't figure out how to do it in my project.
Have faced similar requirement and did some POC on this and definitely moving forward with it . I worked on with each .aspx page as stand alone angular 2 SPA app. This means each aspx page will have its own App.Component.ts and main.ts file(file name based on Angular 2 documentation). main.ts file contains the code to bootstrap the application (sample code below) so there will be a main.ts file for each .aspx page.
import {bootstrap} from 'angular2/platform/browser';
import {HTTP_BINDINGS} from 'angular2/http';
import {HomeComponent} from './home.component';
bootstrap(HomeComponent, [HTTP_BINDINGS])
.catch(err => console.error(err));
There will be one app.component.ts(named it home.component.ts for my home.aspx) file for each aspx page.
Now in the config file which contains Sytem.config details i defined new map and package entry for my home.aspx as shown below:
System.config({
transpiler: 'typescript',
typescriptOptions: {
emitDecoratorMetadata: true,
experimentalDecorators: true
},
map: {
app: '../../Javascript/angular/app',
home: '../../Javascript/angular/home'
},
packages: {
app: { main: './main.ts', defaultExtension: 'ts'},
home: { defaultExtension: 'ts' }
}
});
And finally I moved the System.import code part to .aspx page(code below). Each page will import its own package defined in sytem.config.
<script>
System
.import('home/main-home')
.catch(console.error.bind(console));
</script>
here i have named my main.ts as main-home.ts.
Hopefully this helps you and others. Also i am open for suggestion and review/alternate solution of this approach.
For reference please see: bootstrapping-multiple-angular-2-applications-on-the-same-page
I totally agree with #pawan's answer but yes #pawan i found a nice solution of this. This solution definitely helped me and hope it will help all of you too.
We don't need to create main.ts and AppComponent.ts for each and every page.
We need to make our main component which we are bootstrapping dynamic. In our case, in app.component.ts, i am bootstrapping our component dynamically based on url of current page.
Let's say if your page is home.aspx then boostrap HomeComponent or about.aspx then boostrap AboutComponent
I am doing it by implementing ngDoBootstrap method as following.
export class AppModule {
url : string;
constructor(#Inject(DOCUMENT) private document: any){
this.url = this.document.location.href.toLowerCase();
}
ngDoBootstrap(app:ApplicationRef){
if(this.url.indexOf("home.aspx") > 0){
app.bootstrap(HomeComponent);
}
else if(this.url.indexOf("about.aspx") > 0){
app.bootstrap(AboutComponent);
}
}
}
This is how based on page url, we can dynamically bootstrap our Component and save a lot files of main.ts and app.component.ts for each page.
For this, you need to add entry for each component into entryComponents array of NgModule as below:
#NgModule({
entryComponents : [
HomeComponent,
AboutComponent,
]
})
Hope this helps.
change your index.html base route to your webpage
<base href="/YourWebPageRoute">
include the page inside the webform
<% Response.WriteFile("index.html"); %>
So I was wiring up my AngularUI State Views using the following code
$stateProvider
.state('dash.landing', {
url: '/',
templateUrl: '/partials/backup/dash/landing.html',
controller: 'LandingController'
})
.state('dash.order', {
url: '/overview',
templateUrl: '/partials/backup/dash/order/index.html',
controller: 'OrderController'
})
.state('dash.order.overview', {
url: '/overview',
templateUrl: '/partials/backup/dash/order/overview.html',
controller: 'OverviewController'
})
.state('dash.order.email-accounts', {
url: '/email-accounts',
templateUrl: '/partials/backup/dash/order/email-accounts.html'
})
.state('dash.order.alerts', {
url: '/alerts',
templateUrl: '/partials/backup/dash/order/alerts.html'
});
And for some reason my views were not being rendered and I was getting a $stateNotFound error telling me it could not find dash.landing. After 15 minutes of pulling my hair out I simply changed dash.landing' to just bedashand all of a sudden it worked perfectly! Can someone please explain why I can't usedash.landing` for the root route state name?
Yes, ui-router uses dot notation to implement parent/child relationships among views. You can use dot notation with the default routeProvider to name routes. You can also use dot notation to name application modules, letting other developers know there is a organizational hierarchy in place.
Hi I am trying to add css dynamically but it's not working bellow is my code
angular.module('myApp', [ 'myApp.controllers','myApp.services']).
config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/new', { templateUrl: 'partials/add.html', controller: 'add' ,resolve: {
style : function(){
/* check if already exists first - note ID used on link element*/
/* could also track within scope object*/
alert("DSAF");
angular.element('head').append(' <link rel="stylesheet" href="css/app.css"/>');
}
}}) }]);
Without more info on your code it will be difficult to help but anyway here are a two (easy) things that come to my mind :
Be sure that the path css/app.css redirects to a file i.e no 404,
angular.element('head') will work only if jquery is loaded before angular otherwise you will have an error regarding jqLite.
Finally I have assemble a plunker here where everything is working the way it should base on your extract of code. Let me know if it helps.