Skip to content

Instantly share code, notes, and snippets.

View chandermani's full-sized avatar

Chandermani chandermani

  • London
View GitHub Profile
element.bind('blur', function () { //some third party component directive
scope.$apply(function(){
$scope.model='someData'; //scope updates have to be done inside the $apply callback
});
});
//The incorrect way
var employees=$resource('url').query(); //this is async call. Return value of the call is a empty array []
console.log(employees.length); //This is immediately executed so length is 0. Data gets filled in future.
//Right way
$resource('url').query().then(function(data) {
employees = data;
});
$http({method: 'GET', url: '/someUrl'})
.success(function(data) {
$scope.foo = data;
});
<!--In HTML-->
<p>{{foo}}</p>
$scope.foo = $http({method: 'GET', url: '/someUrl'});
<!--In HTML this works-->
<div>{{foo}}</div>
@chandermani
chandermani / web.config
Created January 22, 2014 16:04
ASP.Net Identity - Google OpenId redirect endpoint.
<location path="signin-google">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
.directive('myDirective', function () {
return {
restrict: 'E',
scope: {
model: '='
},
// The linking function will add behavior to the template
link: function (scope, element, attrs) {
}
};
<div id='userData'>
<div id='sectionParticulars' ng-include="'particularsTemplate'" ng-init='model=model'></div>
<div id='sectionAddress' ng-include="'addressTemplate'" ng-init='model=model.address'></div>
<div id='sectionDepedents' ng-include="'dependentTemplate'" ng-init='model=model.dependents'></div>
</div>
<script type="text/ng-template" class="template" id="particularsTemplate">
<!-- HTML related to user particulars-->
</script>
function SomeCtrl($scope) {
$scope.countries = ['can', 'usa', 'fra', 'jap'];
$scope.user = {name: "Evil Trout"};
$scope.age = 34;
// Our template now can render {{age}}, {{user.name}} and a list of countries!
}
@chandermani
chandermani / Autofacbootstrap.cs
Created December 2, 2012 07:48
Autofac Bootstrap template
public class AutofacBootstrap
{
internal static void Init(ContainerBuilder builder)
{
}
}
@chandermani
chandermani / AutofacIntegration
Created December 2, 2012 07:44
Autofac integration ASP.Net MVC, WebAPI
private void RegisterIOC()
{
var builder = new ContainerBuilder();
builder.RegisterControllers(typeof(MvcApplication).Assembly);
builder.RegisterApiControllers(typeof(MvcApplication).Assembly);
AutofacBootstrap.Init(builder);
var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
GlobalConfiguration.Configuration.DependencyResolver = new Autofac.Integration.WebApi.AutofacWebApiDependencyResolver(container);
}