Adding / Removing components on the fly

As suggested by Tim, quoting @tbosch’s comment Angular reuses previously created DOM elements by default So to avoid this behavior, taken from the comment as well, you can use APP_VIEW_POOL_CAPACITY and assign it 0 as value. bootstrap(MyApp, [provide(APP_VIEW_POOL_CAPACITY, {useValue: 0})]) Update Note that since beta.1 APP_VIEW_POOL_CAPACITY was removed by #5993 and the DOM is being … Read more

Null-coalescing operator returning null for properties of dynamic objects

This is due to obscure behaviors of Json.NET and the ?? operator. Firstly, when you deserialize JSON to a dynamic object, what is actually returned is a subclass of the Linq-to-JSON type JToken (e.g. JObject or JValue) which has a custom implementation of IDynamicMetaObjectProvider. I.e. dynamic d1 = JsonConvert.DeserializeObject(json); var d2 = JsonConvert.DeserializeObject<JObject>(json); Are actually … Read more

How to create class objects dynamically?

The correct answer depends on the number of different classes of which you want to create the instances. If the number is huge (the application should be able to create an instance of any class in your application), you should use the reflection functionality of .Net. But, to be honest, I’m not a big fan … Read more

C# dynamic type gotcha

The fundamental principle of “dynamic” in C# is: at runtime do the type analysis of the expression as though the runtime type had been the compile time type. So let’s see what would happen if we actually did that: dynamic num0 = ((Program.Factory.Empty)container).Value; That program would fail because Empty is not accessible. dynamic will not … Read more

Determine if Any.Type is Optional

Assuming that what you are trying to do is something like this: let anyType: Any.Type = Optional<String>.self anyType is Optional<Any>.Type // false Sadly swift currently (as of Swift 2) does not support covariance nor contravariance and type checks directly against Optional.Type cannot be done: // Argument for generic parameter ‘Wrapped’ could not be inferred anyType … Read more

Dynamic fields in Django Admin

Here is a solution to the problem. Thanks to koniiiik i tried to solve this by extending the *get_fieldsets* method class ProductAdmin(admin.ModelAdmin): def get_fieldsets(self, request, obj=None): fieldsets = super(ProductAdmin, self).get_fieldsets(request, obj) fieldsets[0][1][‘fields’] += [‘foo’] return fieldsets If you use multiple fieldsets be sure to add the to the right fieldset by using the appropriate index.

How can I convert a DataTable into a Dynamic object?

class Program { static void Main() { var dt = new DataTable(); dt.Columns.Add(“ID”, typeof(int)); dt.Columns.Add(“Name”, typeof(string)); dt.Rows.Add(1, “x”); dt.Rows.Add(2, “y”); List<dynamic> dynamicDt = dt.ToDynamic(); Console.WriteLine(dynamicDt.First().ID); Console.WriteLine(dynamicDt.First().Name); } } public static class DataTableExtensions { public static List<dynamic> ToDynamic(this DataTable dt) { var dynamicDt = new List<dynamic>(); foreach (DataRow row in dt.Rows) { dynamic dyn = new … Read more