w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
AngularJS - evaluate a cookie in routes & template
There are many ways, I have two that are my favorite: 1) Check on route change angular.module('MyApp', []) .run(function($rootScope, myLoginService) { $rootScope.$on('$routeChangeStart', function () { if (!myLoginService.isUserLoggedIn()) { $location.path('/login'); } }); You can replace the isUserLogged for a mapper service that receives where the user wants to go; if the user has the proper privileges (either stored within a cookie or local storage in the form of a token), then let the route succeed. Otherwise, show an error, or route him to wherever you want. In my case, the myLoginService checks for a localStorage. 2) Any data request to a server has a token included to headers; failed requests (401) are intercepted and stored, while the user is redirected This one is mor

Categories : Javascript

AngularJS routes with parameters in path not loading in HTML5 mode when going directly to URLs
The angular docs for the $location service state that using HTML5 mode requires you to use URL rewriting on the server side to rewrite all your links to the entry point of your application (e.g. index.html) If you were using Apache to serve your application then you could set up a .htaccess file like so: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^test/[0-9]+$ index.html [L] This would redirect requests like /test/<number> to index.html and angular should be able to route it properly.

Categories : Angularjs

Specific directive (AngularJS) or some template loading before all scripts get content
There are so many ways to go about this: 1) You can create a loading mask that covers everything in your application and has a ng-hide binded to a variable that is in the rootscope and gets set to true at .run(). This way when Angular loads and initializes you get the loading mask hidden. No need for a directive, no nothing. 2) You can have a directive that hides itself. This way, before angular gets initialized, the loading element shows up on the page. Then, after initialization, the directive applies some sort of CSS class on the loading element and fades it out and then removes it from the dom. 3) You can have a special loading div that remains active even after the framework has loaded (maybe you have an ajax request that needs to complete as well). In this case, 1) can work the s

Categories : Angularjs

AngularJS: Protecting routes with angularjs depending if the user is authorized?
Using resolves should help you out here: (code not tested) angular.module('app' []).config(function($routeProvider){ $routeProvider .when('/needsauthorisation', { //config for controller and template resolve : { //This function is injected with the AuthService where you'll put your authentication logic 'auth' : function(AuthService){ return AuthService.authenticate(); } } }); }).run(function($rootScope, $location){ //If the route change failed due to authentication error, redirect them out $rootScope.$on('$routeChangeError', function(event, current, previous, rejection){ if(rejection === 'Not Authenticated'){ $location.path('/'); }

Categories : Angularjs

AngularJS directive template with validation, ngModel and ngClass only works when template is wrapped
At a guess as to what's the problem - Angular is adding validation classes to the first wrapping div it can. In the first one, this one is just an empty wrapper and the extra validation classes causes no problems. The second one already has both class and ng-class attributes in the first wrapper div, and Angular adding validation classes overwrites or conflicts with the ng-class rules causing them not to run and 'has-error' not to be applied. I'm not sure if there's a better solution than just keeping the wrapper div though.

Categories : Angularjs

Angular reload Template + Controller without using Routes
I would suggest looking into the Angular UI Router written by the same guys who wrote angular. It will let you transition to different states which is what it sounds like you are trying to do. https://github.com/angular-ui/ui-router

Categories : Javascript

Angularjs - how to access an ng-include template's data to modify it through another template within the same controller
can you check this fiddle I edited from yours and let me know if it's what you want! angular.module("myApp", []).controller("MainController", ['$scope', function($scope) { $scope.currentQuestion = null; $scope.questions = [ { name: 'question 1', fields:['option 1', 'option 2'] }, { name: 'question 2', fields:['option 3', 'option 4', 'option 5'] }, ]; $scope.setCurrentquestion = function(question){ $scope.currentQuestion = question; } }]);

Categories : Angularjs

Using AngularJS RouteParams with variable routes
Since the URLs aren't for a specific item and can have multiple I would go with a URL more like itemDetail?item=item1&item=item2&item=item3 and then with $routeParams you should get $routeParams.item = [item1, item2, item3]

Categories : Javascript

Inject routes dynamicall in angularjs
There are two ways: Option 1 modifying the routes object directly, as suggested in http://stackoverflow.com/a/13173667/17815 $route.routes['/dynamic'] = {templateUrl: 'dynamic.tpl.html'}; Be careful: you need to add both "/newurl" and "/newurl/" (with trailing slash). see the angular code: this.when = function(path, route) { routes[path] = extend({reloadOnSearch: true}, route); // create redirection for trailing slashes if (path) { var redirectPath = (path[path.length-1] == '/') ? path.substr(0, path.length-1) : path +'/'; routes[redirectPath] = {redirectTo: path}; } return this; }; Option 2 you can keep a reference to $routeProvider: var $routeProviderReference; var app = angular.module('myApp', ['myApp.controllers']); app.config(['$routeProvider', function(

Categories : Angularjs

AngularJS nested routes example questions
ui-router doesn't fully support this. You may check this library for nested routing: http://angular-route-segment.com It provides the functionality for creating tree-like routing hierarchy which can be changed without losing the state. $routeSegmentProvider. when('/section1', 's1.home'). when('/section1/prefs', 's1.prefs'). when('/section1/:id', 's1.itemInfo.overview'). when('/section1/:id/edit', 's1.itemInfo.edit'). when('/section2', 's2'). segment('s1', { templateUrl: 'templates/section1.html', controller: MainCtrl}). within(). segment('home', { templateUrl: 'templates/section1/home.html'}). segment('itemInfo', { templateUrl: 'templates/section1/item.html', controller: Section1ItemCtrl, dependencies: ['id']}

Categories : Angularjs

Configure angularjs routes at runtime
It should be something like: .when('/:prefix/foo', {templateUrl: 'details.html', controller: DetailsCtrl}) The prefix will then be available in the controller through $routeParams. If you would like it to handle the option foo without a prefix just simply place it in the routing and make sure it is before the example above. .when('/foo', {templateUrl: 'details.html', controller: DetailsCtrl}) .when('/:prefix/foo', {templateUrl: 'details.html', controller: DetailsCtrl})

Categories : Angularjs

angularjs routes and param and controller
First of all, your question is incomplete. You have not posted the partial that loads when you navigate to the URL "/list/result/1256", i.e. your templateUrl is missing. Secondly, you have not posted how you are trying to extract the param in ListController. Per my knowledge, var param = parseInt($routeParams['param'], 10); should help you extract the param.

Categories : Angularjs

AngularJS HTML5 nested routes
For single page apps, this is all you need in your NGINX config: server { server_name example.com *.example.com; access_log /var/log/nginx/example.com.access.log; error_log /var/log/nginx/example.com.error.log; root /var/www/html/example; index index.html; location / { try_files $uri /index.html; } }

Categories : HTML

How to add dynamic prefix to AngularJS routes
I think the best option will be to have a the urls to be something like http://mysite.com/somepath?lang=en and then you can just read lang directly from the url wherever you need to.

Categories : Angularjs

How to create routes to full page New / Edit template in EmberJS
I've come across this 'problem' several times when building toy applications. My solution has been to add a template for the resource. So for example, if you were building an address book, your current problem/solution looks like: App.Router.map(function() { this.resource('person', { path: '/person' }, function() { this.route('index', { path: '/' }); this.route('edit', { path: '/:person_id/edit' }); }); }); And your templates might look like: <script type="text/x-handlebars" data-template-name="person/index"> <ul> {{#each model}} <li>{{name}} - {{#linkTo person.edit this}}Edit{{/linkTo}}</li> {{/each}} </ul> {{outlet}} </script> <script type="text/x-handlebars" data-template-name="person/edit"&

Categories : Ember Js

How to use an angularjs resource for rails/RESTful routes?
Have a look at restangular, its specifically designed to make HTTP verb requests to any REST api simple & easy. https://github.com/mgonto/restangular

Categories : Ruby On Rails

how to use AngularJS routes with Haml templates in a Rails app
I got something working without $templateCache. I made a config/initializers/haml.rb file with the following: Rails.application.assets.register_engine '.haml', Tilt::HamlTemplate Then in my config/application.rb, I added config.assets.paths << Rails.root.join('app', 'assets', 'templates'). I also renamed my template file from api-list.haml to api-list.html.haml. My routes look like this now: api_app.config(['$routeProvider', ($routeProvider) -> $routeProvider.when '/', templateUrl: '/assets/api-list.html' controller: api_app.ApiListController $routeProvider.otherwise redirectTo: '/' ]) I don't like having /assets hard-coded in there, so I may end up changing this file from routes.js.coffee to routes.js.erb and using Rails helpers to get a path.

Categories : Javascript

AngularJS and nodeJs Express: routes and refresh
Try use the specify the templateUrl with the absolute path from the root of the views. For example, suppose you have configured and views is in the public folder app.set('views', __dirname + '/public'); then change the path to the template to /public/page/home.html

Categories : Javascript

Can angularjs routes have optional parameter values?
Actually I think OZ_ may be somewhat correct. If you have the route '/users/:userId' and navigate to '/users/' (note the trailing /), $routeParams in your controller should be an object containing userId: "" in 1.1.5. So no the paramater userId isn't completely ignored, but I think it's the best you're going to get.

Categories : Angularjs

AngularJS HTML sub routes not showing when url typed in
It appears to be a bug in Angular 1.1.5 that is effecting URL parsing in HTML5 routes. Rolling back to 1.1.4 fixes the problem. More information here: https://github.com/angular/angular.js/issues/2833

Categories : Javascript

AngularJS authenticating multiple routes with resolve
the suggestion by Gloopy was very interesting, and i may implement a similar approach in the future. For now i have taken a much simpler approach: gm.config(['$routeProvider', 'PathProvider', function($routeProvider, PathProvider) { var authResolver = { // although this does work there could be a better way to do this. 'auth' : function(AuthenticationService) { return AuthenticationService.isLoggedIn(); } }; $routeProvider.when('/authenticatedRoute', { templateUrl: PathProvider.view('application/dashboard/index.html'), controller: 'dashboardController', resolve: authResolver }); $routeProvider.otherwise({ redirectTo: '/dashboard', resolve: authResolver }); }]);

Categories : PHP

Unit testing AngularJS routes throwing Error: Unexpected request
This means that there is an AJAX call that goes to fetch the template. $httpBackend.expectGET('app/html/listTodos.html').respond(200) can be put before calling path(): describe("Todo Routes", function(){ var route; var rootScope; var location; var httpBackend; beforeEach(function(){ module('todoApp'); inject(function($route, $location, $rootScope, $httpBackend){ route = $route; location = $location; rootScope = $rootScope; httpBackend = $httpBackend; }); }); it("should navigate to todo list", function(){ httpBackend.expectGET('app/html/listTodos.html').respond(200);//mimicking the AJAX call expect(route.current).toBeUndefined(); location.path('/todos');

Categories : Unit Testing

Knockout template not loading?
I think you would need to call ko.applyBindings() again. But the usual approach in Knockout is to put the div in your HTML and use the visible binding to control whether the div is rendered.

Categories : Javascript

$routeProvider not loading template when url has a parameter
You need to make your partials absolute as in: templateUrl: '/views/item.html', When a parameter is added it looks at it as another depth of directory and wants to load something like /item/views/item.html

Categories : Angularjs

Symfony2 Twig template - css not loading
First execute app/console assets:install ( consider adding --symlink ). The command will copy/symlink all your bundle's Resources/public to web/bundles and create a folder in there named as the lowercase bundle-name without a trailing "Bundle". example: YourAwesomeBundleResourcespubliccssstyle.css will be copied/symlinked to webundlesyourawesomecssstyle.css ... afterwards include the assets using asset("@YourBundle/Resources/public/css/style.css") ... or asset("bundles/your/css/style.css")

Categories : CSS

Drupal 7: Appropriate page template not loading
Ok. The problem is ALL '-' characters need to be replaced with '_' in the template preprocessor, not just the ones between alias path parts. So the '-' between 'annual' and 'reports' had to be replaced also. So the for loop in my preprocessor looks like this now: foreach ($alias as $path_part) { if(is_numeric($path_part)){ $variables['theme_hook_suggestions'][] = $template_filename . '__%'; } $template_filename = $template_filename . '__' . preg_replace("/-/", "_", $path_part); $variables['theme_hook_suggestions'][] = $template_filename; }

Categories : PHP

Is the "loading" template special in Ember.js?
As you already noticed the router needs no definition for the LoadingRoute since it's somewhat special. The LoadingRoute will be looked up by ember, and if it's find one it is used for exact the expected behavior. Have a look at this jsbin for an simulated loading example. Are there other special template names? Yes, there is also a special route called FailureRoute which can be used to handle errors globally. Where is this magic documented? (not possible to find it in the Ember documentation) As for some documentation on this please see this gist. Some of the changes where introduced not long ago, so documentation is somewhat sparse. Hope it helps.

Categories : Ember Js

Angular.js scope issues during template loading
Loading the template use URL, Angularjs creates an additional transcluded scope I guess. Try to use $$prevSibling.$$prevSibling to access the functions. Btw, it is really hacky to use $$prevSibling. <div authorization><a href="#" ng-click="$$prevSibling.$$prevSibling.modalToggle()">Sign in</a></div> <div registration><a href="#" ng-click="$$prevSibling.$$prevSibling.modalToggle()">Registration</a></div>

Categories : Angularjs

How to leave my general "Routes" intact when operating code in a specific "Area" with its own "Routes"?
When you have areas in your app you will need to be specific about which controllers and actions you want to point to. If you are inside your SubApp area, then any link you need to create pointing to the root, should include an empty area. @Url.Action("index", "home", new { area = "" } Using the same concept, any url from the root controllers to the SubApp area should include the area in the link: @Url.Action("index", "home", new { area = "SubApp" } If you are not crossing any boundaries, then not specifying the area will default to the area you are in.

Categories : Asp Net Mvc

Iteration Through Routes Mapped to RouteTable.Routes via MapHttpRoute - MVC4 Web API
If you are looking to iterate only through Web API route collection, you could do something like GlobalConfiguration.Configuration.Routes to get HttpRouteCollection. This collection would have all your api routes.

Categories : Asp Net

Rails Routes. Multiple nested routes with member actions
Delete the comma between resources :milestones and resources :comments. Your code should be resources :projects do resources :milestones resources :comments do member {post :hide} end end

Categories : Ruby On Rails

How to enable format in routes with ServiceStack in tandem with custom routes?
See the wiki page on Routing for documentation on how Routing works, e.g. if you wanted to use pre-defined routes the correct urls would be: /api/json/reply/Things /api/json/reply/things?Id=1 /api/xml/reply/Things /api/xml/reply/things?Id=1 Note: the pre-defined only uses the name of the Request DTO, i.e. it does not use all your custom routes. The Content Negotiation section on Routing wiki shows the different ways to request different Content-Types. In ServiceStack (v3.9.54+) you can now use a format .ext e.g: /api/things.json /api/things/1.json /api/things.xml /api/things/1.xml Which is an alternative to using the ?format=ext parameter: /api/things?format=json /api/things/1?format=json /api/things?format=xml /api/things/1?format=xml

Categories : Rest

Underscore template throwing error when loading via ajax
the ajaxify script loads scripts asynchronously on ajax success. The issue was that it was creating a <script> node without the type or id attributes. Here is the ammended script excerpt from ajaxify.js // Add the scripts $scripts.each(function(){ var $script = $(this), scriptText = $script.text(), scriptType = $script.attr('type'), scriptId = $script.attr('id'); scriptNode = document.createElement('script'); if(scriptType) { $(scriptNode).attr('type', scriptType); } if(scriptId) { $(scriptNode).attr('id', scriptId); } scriptNode.appendChild(document.createTextNode(scriptText)); contentNode.appendChild(scriptNode); });

Categories : Javascript

Jenkins PHP Template - Display's loading message and blocks UI
I've just had the same issue, I'm using version 1.523 of Jenkins on an Ubuntu server. The solution I found was to manually edit the project config.xml file. sudo vim /var/lib/jenkins/jobs/yourProjectName/config.xml I had images in the description and I removed those leaving the description tag empty. I also had an empty plot section which I removed completely from the publishers section. After saving the config and going back to 'manage Jenkins' and then 'Reload Configuration from Disk' I then reopend my project and the config opened normally again. I wasn't getting quite the same error message as you in the browser console to start with, but I hope that helps.

Categories : PHP

AngularJS Loading a page into a div
Use ng-include: <ng-include src="{string}" [onload="{string}"] [autoscroll="{string}"]> </ng-include> http://docs.angularjs.org/api/ng.directive:ngInclude

Categories : Angularjs

Rails 2 + Spree 0.11.0: How do routes work when there are so many routes files?
Routes should be specified in config/routes.rb Here's where they're specified in Spree 0.11.0: https://github.com/spree/spree/blob/v0.11.0/config/routes.rb Modern versions of Spree are mountable Rails engines which will mount some of its own routes underneath your applications routes. However, you're dealing with the rails 2 version which injects its routes a little differently. You're dealing with a very old version of Spree, so many of the resources you find on the internet will pertain to more modern versions of Spree (Rails 3.0+). Your easiest bet will be to figure out where 'gourmet-specialties' is coming from and remove it. If it's coming from the taxonomy tree, try recategorizing it under the root taxon.

Categories : Ruby On Rails

PHP: Loading a html template from a .txt file and replacing the tag before sending an Email
You are missing a few string concatenation operators, look at your error message: PHP Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/username/public_html/example/fnc/mailer.php on line 5 function mailer_send($mailer_recipient, $mailer_subject, $mailer_message){ $mailer_headers = "From: webmaster@example.co.uk" . " " . "X-Mailer: PHP/" . phpversion() . " " . "MIME-Version: 1.0 " . "Content-Type: text/html; charset=ISO-8859-1 "; mail($mailer_recipient, $mailer_subject, $mailer_message, $mailer_headers); }

Categories : PHP

Loading underscore template via ajax loses html, need to escape "<", ">"
Curious situation. The simple solution would be to use .html() and unescape escaped underscore sequences, which is probably what you want (i.e. you probably don't want to unescape everything): $script.html().replace(/&lt;%/gi, '<%').replace(/%&gt;/gi, '%>')

Categories : Javascript

delayed loading of template file inside bootstrap modal
I found the following solution to this issue: <?php echo $this->getLayout()->createBlock('moduleName/blockType')->setTemplate('moduleName/templateName.phtml')->toHtml(); ?> It's probably the least elegant way of doing this in Magento but it works. I'm sure the better way would be to use local.xml inside of the layout directory within your theme, but I can't figure it out at the moment on my own.

Categories : PHP

AngularJS loading controllers from folder
You can put the your code where you wants to. If you put them into angular modules, angular will find it. So if you have a service in /app/common/services/foo.js like: angular.module('app').service('foo', function() { ... }); You can do this in the userController: angular.module('app').controller('UserController', function($scope, foo) { ... }); Here you see how I injected foo in our controller. Angular Dependency Injection system is smart enough to find your code no matter where you put them. You can also create different modules than app, you can have: angular.module('other').service('bar', function() { ... }); And where you define the app module, something like this: angular.module('app', []); You just need to add the new module there as a dependency, that is what the [] ar

Categories : Javascript



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.