Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/nativescript-angular/view-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,21 @@ export function setProperty(view: NgView, attributeName: string, value: any): vo
} else if (propMap.has(attributeName)) {
// We have a lower-upper case mapped property.
let propertyName = propMap.get(attributeName);
view[propertyName] = value;
view[propertyName] = convertValue(value);
} else {
// Unknown attribute value -- just set it to our object as is.
view[attributeName] = value;
view[attributeName] = convertValue(value);
}
}

function convertValue(value: any): any {
var valueAsNumber = +value;
if (!isNaN(valueAsNumber)) {
return valueAsNumber;
} else if (value && (value.toLowerCase() === "true" || value.toLowerCase() === "false")) {
return value.toLowerCase() === "true" ? true : false;
} else {
return value;
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/app/tests/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {Component} from "angular2/core";
export class SimpleApp {
}

describe('bootstrap', () => {
describe('Bootstrap E2E', () => {
it('SimpleApp bootstrapped', () => {
return bootstrap(SimpleApp).then((componentRef) => {
assert.isTrue(SimpleApp === componentRef.componentType);
Expand Down
45 changes: 45 additions & 0 deletions tests/app/tests/property-sets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//make sure you import mocha-config before angular2/core
import {assert} from "./test-config";
import {bootstrap} from "../nativescript-angular/application";
import {Component} from "angular2/core";
import {View} from "ui/core/view";
import {NgView, ViewExtensions, setProperty} from "../nativescript-angular/view-util";
import {Red} from "color/known-colors";

class TestView extends View implements ViewExtensions {
public nodeName: string = "TestView";
public templateParent: NgView = null;
public cssClasses: Map<string, boolean> = new Map<string, boolean>();

public stringValue: string = "";
public numValue: number = 0;
public boolValue: boolean = undefined;
}

describe('setting View properties', () => {
it('preserves string values', () => {
let view = new TestView();
setProperty(view, "stringValue", "blah")
assert.equal("blah", view.stringValue);
});

it('converts number values', () => {
let view = new TestView();
setProperty(view, "numValue", "42")
assert.strictEqual(42, view.numValue);
});

it('converts boolean values', () => {
let view = new TestView();
setProperty(view, "boolValue", "true")
assert.strictEqual(true, view.boolValue);
setProperty(view, "boolValue", "false")
assert.strictEqual(false, view.boolValue);
});

it('sets style values', () => {
let view = new TestView();
setProperty(view, "style", "color: red")
assert.equal(Red, view.style.color.hex);
});
});
2 changes: 1 addition & 1 deletion tests/app/tests/renderer-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class StyledLabelCmp {
}
}

describe('bootstrap', () => {
describe('Renderer E2E', () => {
let appComponent: App = null;
let _pendingDispose: ComponentRef[] = [];

Expand Down