Posts

Watching a single property in an array in AngularJS

A typescript example that converts the array's property into a single string that can be watched. $scope . $watch ( () => this . someArray . map ( x => x . selected ? "1" : "0" ). join ( "" ), ( newValue , oldValue , scope ) => this . onSelectionChanged ( this . getSelectedItems ()));

Getting an AngularJS directive to call back a method on its parent's controller

Here is a TypeScript example of how to call back a method on the controller from an embedded directive. The most important thing to note is that the directive's parameter name for your callback uses a & when defined, and when calling that callback you should not use positional parameters but instead use an object with properties having the names of the parameters in the target. Register the directive when you create your app module: module MyApp { var app : angular . IModule = angular . module ( "MyApp" ); MyApp . Directives . FileUploader . register ( app ); } The registration code is as follows: module MyApp . Directives . FileUploader { class FileUploaderDirective implements angular . IDirective { public restrict : string = "E" ; public templateUrl : string = "/app/Directives/FileUploader/FileUploaderDirective.html" ; //IMPORTANT - Use & to identify this as a method reference

AngularJs - binding HTML

The directive ng-bind will escape HTML to avoid data acting maliciously. If you want to output html you need to use ng-bind-html <div ng-bind-html="someHtmlBody"/> The important step to getting this working is to ensure the script angular-sanitize.js is referenced on your page, and it is specified as a dependency when creating a module.... var app = angular.module("MyApp", ["ngSanitize", "OtherDependencies"]);

AngularJS routes with ASP MVC Forms authentication

The ASP MVC app I am working on uses forms authentication with a timeout. This means that when the session has timed out and the user clicks refresh they get redirected to a login page, and after that they get directed back to the original page without the deep-linked client-side # part of the url.  The solution to this is as follows: The first thing to do is to have the ASP MVC server side capture any URLs that should related to your client-side angular routing and return the single-page app HTML. When registering your ASP MVC routes add the following rule routes . MapRoute ( name : "Angular" , url : "x/{*clientPath}" , Where the "x/" is the base part of your client app, of course you can do without the "x" in the URL if your entire app is a single-page angular app, in which case you will need to add a preceding rule to render your ASP MVC server side account-login page. Then in your Angular app make

Node.js Express, form validation, and keeping previously posted form values

I've been playing with Node.js and the Express webserver framework as a learning experience, it's good fun :) In the C# ASP MVC world using the Razor view engine I can define my user interface elements like this... @Html.TextBoxFor(x => x.EmailAddress) @Html.ValidationMessageFor(x => x.EmailAddress) This will do three things It will create the html output for an input element If the view is being rendered as a result of a POST it will set the value of the input to the value posted.  This is useful for when you have a form validation error and don't want to have to force the user to re-enter all of their input. If there is an error message registered for EmailAddress it will display the error text *Note that error messages are registered using ModelState.AddModelError("EmailAddress", "The error message") Node.js, Express, and Jade Express is a very light weight framework so doesn't do any of this stuff for you, so I had to h

AngularJS - Triggering code whenever ng-view updates

//Create the module var app = angular.module('someapp', ['ngRoute']); //Config the routes app.config(configRoutes); function configRoutes($routeProvider) { $routeProvider .when('/', { templateUrl: '/angular/viewtemplates/admin/index.html', controller: 'AdminController' }) .when('/categories', { templateUrl: 'angular/viewtemplates/admin/categories/index.html', controller: 'CategoryIndexController' }) } //Make sure we are notified whenever the ng-view is updated app.run(function($rootScope) { $rootScope.$on('$viewContentLoaded', function() { $('table[data-toggle="table"]').bootstrapTable(); }); });

Windows welcome screen slow

Image
After I log in to Windows 7 the welcome screen stays on for ages, in the past it was almost instant.  I’ve tried various suggestions from forums and none of them worked, then it struck me what it was! Windows was trying to reconnect network drives after I had logged in, but one of them (a connection to my iMac) was unobtainable because my iMac was off.  I disconnected the mapped network drives and speed is back to normal