From f39c9c9e75671a7e235734b6b8aef263f6dff254 Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Wed, 8 Jun 2016 16:38:52 -0700 Subject: [PATCH] style(lint): re-format modules/@angular --- gulpfile.js | 2 +- .../@angular/common/src/common_directives.ts | 4 +- modules/@angular/common/src/directives.ts | 8 +- .../common/src/directives/core_directives.ts | 10 +- .../common/src/directives/ng_class.ts | 43 +- .../@angular/common/src/directives/ng_for.ts | 42 +- .../@angular/common/src/directives/ng_if.ts | 4 +- .../common/src/directives/ng_plural.ts | 21 +- .../common/src/directives/ng_style.ts | 18 +- .../common/src/directives/ng_switch.ts | 19 +- .../src/directives/ng_template_outlet.ts | 4 +- .../@angular/common/src/forms-deprecated.ts | 45 +- .../common/src/forms-deprecated/directives.ts | 79 +- .../directives/abstract_control_directive.ts | 5 +- .../directives/checkbox_value_accessor.ts | 5 +- .../directives/control_container.ts | 3 +- .../directives/control_value_accessor.ts | 2 +- .../directives/default_value_accessor.ts | 4 +- .../directives/form_interface.ts | 4 +- .../forms-deprecated/directives/ng_control.ts | 3 +- .../directives/ng_control_group.ts | 27 +- .../directives/ng_control_name.ts | 80 +- .../directives/ng_control_status.ts | 5 +- .../forms-deprecated/directives/ng_form.ts | 31 +- .../directives/ng_form_control.ts | 78 +- .../directives/ng_form_model.ts | 33 +- .../forms-deprecated/directives/ng_model.ts | 72 +- .../directives/normalize_validator.ts | 3 +- .../directives/number_value_accessor.ts | 4 +- .../radio_control_value_accessor.ts | 29 +- .../select_control_value_accessor.ts | 33 +- .../select_multiple_control_value_accessor.ts | 39 +- .../src/forms-deprecated/directives/shared.ts | 54 +- .../forms-deprecated/directives/validators.ts | 11 +- .../src/forms-deprecated/form_builder.ts | 30 +- .../common/src/forms-deprecated/model.ts | 66 +- .../common/src/forms-deprecated/validators.ts | 37 +- modules/@angular/common/src/forms.ts | 45 +- .../@angular/common/src/forms/directives.ts | 102 +- .../directives/abstract_control_directive.ts | 5 +- .../directives/checkbox_value_accessor.ts | 5 +- .../src/forms/directives/control_container.ts | 3 +- .../directives/control_value_accessor.ts | 2 +- .../directives/default_value_accessor.ts | 4 +- .../src/forms/directives/form_interface.ts | 4 +- .../common/src/forms/directives/ng_control.ts | 3 +- .../src/forms/directives/ng_control_group.ts | 27 +- .../src/forms/directives/ng_control_name.ts | 80 +- .../src/forms/directives/ng_control_status.ts | 5 +- .../common/src/forms/directives/ng_form.ts | 31 +- .../src/forms/directives/ng_form_control.ts | 78 +- .../src/forms/directives/ng_form_model.ts | 33 +- .../common/src/forms/directives/ng_model.ts | 72 +- .../forms/directives/normalize_validator.ts | 3 +- .../forms/directives/number_value_accessor.ts | 4 +- .../radio_control_value_accessor.ts | 29 +- .../select_control_value_accessor.ts | 33 +- .../select_multiple_control_value_accessor.ts | 39 +- .../common/src/forms/directives/shared.ts | 54 +- .../common/src/forms/directives/validators.ts | 11 +- .../@angular/common/src/forms/form_builder.ts | 30 +- modules/@angular/common/src/forms/model.ts | 66 +- .../@angular/common/src/forms/validators.ts | 37 +- .../src/location/hash_location_strategy.ts | 13 +- .../@angular/common/src/location/location.ts | 9 +- .../src/location/path_location_strategy.ts | 19 +- modules/@angular/common/src/pipes.ts | 14 +- .../@angular/common/src/pipes/async_pipe.ts | 14 +- .../@angular/common/src/pipes/common_pipes.ts | 15 +- .../@angular/common/src/pipes/date_pipe.ts | 11 +- .../common/src/pipes/i18n_plural_pipe.ts | 6 +- .../common/src/pipes/i18n_select_pipe.ts | 7 +- .../pipes/invalid_pipe_argument_exception.ts | 2 +- .../@angular/common/src/pipes/json_pipe.ts | 4 +- .../common/src/pipes/lowercase_pipe.ts | 7 +- .../@angular/common/src/pipes/number_pipe.ts | 27 +- .../@angular/common/src/pipes/replace_pipe.ts | 13 +- .../@angular/common/src/pipes/slice_pipe.ts | 5 +- .../common/src/pipes/uppercase_pipe.ts | 7 +- .../common/test/directives/ng_class_spec.ts | 744 ++--- .../common/test/directives/ng_for_spec.ts | 826 +++--- .../common/test/directives/ng_if_spec.ts | 398 +-- .../common/test/directives/ng_plural_spec.ts | 163 +- .../common/test/directives/ng_style_spec.ts | 222 +- .../common/test/directives/ng_switch_spec.ts | 209 +- .../directives/ng_template_outlet_spec.ts | 136 +- .../test/directives/non_bindable_spec.ts | 85 +- .../test/forms-deprecated/directives_spec.ts | 275 +- .../forms-deprecated/form_builder_spec.ts | 62 +- .../test/forms-deprecated/integration_spec.ts | 1428 +++++---- .../test/forms-deprecated/model_spec.ts | 574 ++-- .../test/forms-deprecated/validators_spec.ts | 146 +- .../common/test/forms/directives_spec.ts | 275 +- .../common/test/forms/form_builder_spec.ts | 62 +- .../common/test/forms/integration_spec.ts | 1428 +++++---- .../@angular/common/test/forms/model_spec.ts | 574 ++-- .../common/test/forms/validators_spec.ts | 146 +- .../common/test/pipes/async_pipe_spec.ts | 76 +- .../common/test/pipes/date_pipe_spec.ts | 33 +- .../test/pipes/i18n_plural_pipe_spec.ts | 35 +- .../test/pipes/i18n_select_pipe_spec.ts | 26 +- .../common/test/pipes/json_pipe_spec.ts | 57 +- .../common/test/pipes/lowercase_pipe_spec.ts | 22 +- .../common/test/pipes/number_pipe_spec.ts | 29 +- .../common/test/pipes/replace_pipe_spec.ts | 62 +- .../common/test/pipes/slice_pipe_spec.ts | 55 +- .../common/test/pipes/uppercase_pipe_spec.ts | 21 +- modules/@angular/common/testing.ts | 2 +- .../@angular/common/testing/location_mock.ts | 15 +- .../common/testing/mock_location_strategy.ts | 4 +- modules/@angular/compiler-cli/index.ts | 3 +- .../src/a/multiple_components.ts | 7 +- .../integrationtest/src/animate.ts | 40 +- .../compiler-cli/integrationtest/src/basic.ts | 3 +- .../integrationtest/src/bootstrap.ts | 7 +- .../integrationtest/src/features.ts | 2 +- .../integrationtest/src/projection.ts | 8 +- .../integrationtest/test/animate_spec.ts | 16 +- .../integrationtest/test/basic_spec.ts | 26 +- .../integrationtest/test/i18n_spec.ts | 4 +- .../integrationtest/test/projection_spec.ts | 16 +- modules/@angular/compiler-cli/src/codegen.ts | 61 +- .../compiler-cli/src/compiler_private.ts | 2 +- .../@angular/compiler-cli/src/extract_i18n.ts | 159 +- modules/@angular/compiler-cli/src/main.ts | 5 +- .../compiler-cli/src/reflector_host.ts | 34 +- .../src/static_reflection_capabilities.ts | 4 +- .../compiler-cli/src/static_reflector.ts | 191 +- modules/@angular/compiler-cli/test/mocks.ts | 66 +- .../compiler-cli/test/reflector_host_spec.ts | 79 +- .../test/static_reflector_spec.ts | 519 ++-- modules/@angular/compiler/compiler.ts | 30 +- modules/@angular/compiler/core_private.ts | 3 +- modules/@angular/compiler/private_export.ts | 124 +- .../compiler/src/animation/animation_ast.ts | 22 +- .../src/animation/animation_compiler.ts | 291 +- .../src/animation/animation_parser.ts | 265 +- .../src/animation/styles_collection.ts | 8 +- modules/@angular/compiler/src/assertions.ts | 2 +- .../@angular/compiler/src/compile_metadata.ts | 290 +- modules/@angular/compiler/src/compiler.ts | 18 +- modules/@angular/compiler/src/config.ts | 16 +- modules/@angular/compiler/src/css/lexer.ts | 124 +- modules/@angular/compiler/src/css/parser.ts | 100 +- .../src/directive_lifecycle_reflector.ts | 11 +- .../compiler/src/directive_normalizer.ts | 40 +- .../compiler/src/directive_resolver.ts | 27 +- .../compiler/src/expression_parser/ast.ts | 13 +- .../compiler/src/expression_parser/lexer.ts | 60 +- .../compiler/src/expression_parser/parser.ts | 98 +- modules/@angular/compiler/src/html_ast.ts | 18 +- modules/@angular/compiler/src/html_lexer.ts | 49 +- modules/@angular/compiler/src/html_parser.ts | 60 +- modules/@angular/compiler/src/html_tags.ts | 57 +- .../@angular/compiler/src/i18n/expander.ts | 77 +- .../compiler/src/i18n/i18n_html_parser.ts | 113 +- modules/@angular/compiler/src/i18n/message.ts | 7 +- .../compiler/src/i18n/message_extractor.ts | 32 +- modules/@angular/compiler/src/i18n/shared.ts | 71 +- .../compiler/src/i18n/xmb_serializer.ts | 32 +- modules/@angular/compiler/src/identifiers.ts | 83 +- .../compiler/src/metadata_resolver.ts | 184 +- .../@angular/compiler/src/offline_compiler.ts | 108 +- .../compiler/src/output/abstract_emitter.ts | 56 +- .../src/output/abstract_js_emitter.ts | 18 +- .../compiler/src/output/dart_emitter.ts | 21 +- .../compiler/src/output/dart_imports.ts | 5 +- .../compiler/src/output/interpretive_view.ts | 18 +- .../compiler/src/output/js_emitter.ts | 15 +- .../compiler/src/output/output_ast.ts | 146 +- .../compiler/src/output/output_interpreter.ts | 129 +- .../compiler/src/output/output_jit.ts | 9 +- .../@angular/compiler/src/output/path_util.ts | 6 +- .../compiler/src/output/ts_emitter.ts | 34 +- modules/@angular/compiler/src/parse_util.ts | 16 +- .../@angular/compiler/src/pipe_resolver.ts | 5 +- .../@angular/compiler/src/provider_parser.ts | 123 +- .../@angular/compiler/src/runtime_compiler.ts | 105 +- .../src/schema/dom_element_schema_registry.ts | 9 +- .../src/schema/dom_security_schema.ts | 23 +- modules/@angular/compiler/src/selector.ts | 55 +- modules/@angular/compiler/src/shadow_css.ts | 84 +- .../@angular/compiler/src/style_compiler.ts | 41 +- .../compiler/src/style_url_resolver.ts | 26 +- modules/@angular/compiler/src/template_ast.ts | 86 +- .../@angular/compiler/src/template_parser.ts | 436 ++- .../compiler/src/template_preparser.ts | 5 +- modules/@angular/compiler/src/url_resolver.ts | 67 +- modules/@angular/compiler/src/util.ts | 23 +- .../src/view_compiler/compile_binding.ts | 3 +- .../src/view_compiler/compile_element.ts | 174 +- .../src/view_compiler/compile_method.ts | 3 +- .../src/view_compiler/compile_pipe.ts | 18 +- .../src/view_compiler/compile_query.ts | 39 +- .../src/view_compiler/compile_view.ts | 66 +- .../compiler/src/view_compiler/constants.ts | 6 +- .../src/view_compiler/event_binder.ts | 83 +- .../src/view_compiler/expression_converter.ts | 35 +- .../src/view_compiler/lifecycle_binder.ts | 41 +- .../src/view_compiler/property_binder.ts | 163 +- .../compiler/src/view_compiler/util.ts | 25 +- .../compiler/src/view_compiler/view_binder.ts | 61 +- .../src/view_compiler/view_builder.ts | 286 +- .../src/view_compiler/view_compiler.ts | 32 +- .../@angular/compiler/src/view_resolver.ts | 11 +- .../test/animation/animation_compiler_spec.ts | 53 +- .../test/animation/animation_parser_spec.ts | 360 +-- .../compiler/test/compile_metadata_spec.ts | 166 +- .../@angular/compiler/test/css/lexer_spec.ts | 189 +- .../@angular/compiler/test/css/parser_spec.ts | 85 +- .../compiler/test/css/visitor_spec.ts | 69 +- .../compiler/test/directive_lifecycle_spec.ts | 71 +- .../test/directive_normalizer_spec.ts | 291 +- .../compiler/test/directive_resolver_spec.ts | 73 +- .../test/expression_parser/lexer_spec.ts | 87 +- .../test/expression_parser/parser_spec.ts | 292 +- .../test/expression_parser/unparser.ts | 27 +- .../compiler/test/html_ast_spec_utils.ts | 15 +- .../@angular/compiler/test/html_lexer_spec.ts | 797 ++--- .../compiler/test/html_parser_spec.ts | 289 +- .../test/i18n/i18n_html_parser_spec.ts | 300 +- .../test/i18n/message_extractor_spec.ts | 240 +- .../compiler/test/i18n/message_spec.ts | 21 +- .../compiler/test/i18n/xmb_serializer_spec.ts | 69 +- .../test/metadata_resolver_fixture.ts | 2 +- .../compiler/test/metadata_resolver_spec.ts | 35 +- .../test/offline_compiler_codegen_typed.ts | 8 +- .../test/offline_compiler_codegen_untyped.ts | 6 +- .../compiler/test/offline_compiler_spec.ts | 24 +- .../compiler/test/offline_compiler_util.ts | 53 +- .../test/output/abstract_emitter_spec.ts | 11 +- .../compiler/test/output/dart_emitter_spec.ts | 143 +- .../compiler/test/output/dart_imports_spec.ts | 20 +- .../compiler/test/output/js_emitter_spec.ts | 180 +- .../output/output_emitter_codegen_typed.ts | 16 +- .../output/output_emitter_codegen_untyped.ts | 14 +- .../test/output/output_emitter_spec.ts | 315 +- .../test/output/output_emitter_util.ts | 81 +- .../compiler/test/output/ts_emitter_spec.ts | 169 +- .../dom_element_schema_registry_spec.ts | 27 +- .../compiler/test/schema/schema_extractor.ts | 61 +- .../@angular/compiler/test/selector_spec.ts | 55 +- .../@angular/compiler/test/shadow_css_spec.ts | 42 +- .../compiler/test/style_url_resolver_spec.ts | 13 +- .../compiler/test/template_parser_spec.ts | 872 +++--- .../compiler/test/template_preparser_spec.ts | 21 +- .../@angular/compiler/test/test_bindings.ts | 6 +- .../test/test_component_builder_spec.ts | 692 ++--- .../compiler/test/url_resolver_spec.ts | 30 +- .../compiler/test/view_resolver_mock_spec.ts | 9 +- .../compiler/test/view_resolver_spec.ts | 25 +- .../@angular/compiler/test/xhr_mock_spec.ts | 29 +- .../testing/directive_resolver_mock.ts | 6 +- .../compiler/testing/schema_registry_mock.ts | 7 +- .../testing/test_component_builder.ts | 51 +- .../compiler/testing/view_resolver_mock.ts | 7 +- modules/@angular/compiler/testing/xhr_mock.ts | 10 +- modules/@angular/core/index.ts | 33 +- modules/@angular/core/private_export.ts | 54 +- .../animation/active_animation_players_map.ts | 16 +- .../core/src/animation/animation_constants.ts | 2 +- .../core/src/animation/animation_driver.ts | 12 +- .../src/animation/animation_group_player.ts | 7 +- .../core/src/animation/animation_player.ts | 15 +- .../animation/animation_sequence_player.ts | 15 +- .../src/animation/animation_style_util.ts | 96 +- .../@angular/core/src/animation/metadata.ts | 180 +- .../core/src/application_common_providers.ts | 16 +- modules/@angular/core/src/application_ref.ts | 54 +- .../@angular/core/src/application_tokens.ts | 10 +- modules/@angular/core/src/change_detection.ts | 21 +- .../src/change_detection/change_detection.ts | 48 +- .../change_detection/change_detection_util.ts | 9 +- .../core/src/change_detection/constants.ts | 12 +- .../differs/default_iterable_differ.ts | 58 +- .../differs/default_keyvalue_differ.ts | 22 +- .../differs/iterable_differs.ts | 9 +- .../differs/keyvalue_differs.ts | 7 +- modules/@angular/core/src/console.ts | 3 +- modules/@angular/core/src/debug/debug_node.ts | 12 +- .../@angular/core/src/debug/debug_renderer.ts | 24 +- modules/@angular/core/src/di.ts | 34 +- modules/@angular/core/src/di/decorators.ts | 11 +- modules/@angular/core/src/di/forward_ref.ts | 3 +- modules/@angular/core/src/di/provider.ts | 37 +- .../core/src/di/reflective_exceptions.ts | 34 +- .../core/src/di/reflective_injector.ts | 105 +- .../@angular/core/src/di/reflective_key.ts | 4 +- .../core/src/di/reflective_provider.ts | 59 +- modules/@angular/core/src/linker.ts | 12 +- .../core/src/linker/component_factory.ts | 23 +- .../core/src/linker/component_resolver.ts | 15 +- .../@angular/core/src/linker/debug_context.ts | 42 +- .../src/linker/dynamic_component_loader.ts | 45 +- modules/@angular/core/src/linker/element.ts | 22 +- .../@angular/core/src/linker/exceptions.ts | 5 +- .../@angular/core/src/linker/query_list.ts | 9 +- .../src/linker/systemjs_component_resolver.ts | 15 +- .../@angular/core/src/linker/template_ref.ts | 7 +- modules/@angular/core/src/linker/view.ts | 100 +- .../core/src/linker/view_container_ref.ts | 26 +- modules/@angular/core/src/linker/view_ref.ts | 6 +- .../@angular/core/src/linker/view_utils.ts | 96 +- modules/@angular/core/src/metadata.ts | 120 +- modules/@angular/core/src/metadata/di.ts | 30 +- .../@angular/core/src/metadata/directives.ts | 59 +- .../core/src/metadata/lifecycle_hooks.ts | 31 +- modules/@angular/core/src/metadata/view.ts | 29 +- .../core/src/platform_common_providers.ts | 10 +- .../core/src/platform_directives_and_pipes.ts | 4 +- modules/@angular/core/src/profile/profile.ts | 9 +- .../platform_reflection_capabilities.ts | 3 +- .../core/src/reflection/reflection.ts | 7 +- .../src/reflection/reflection_capabilities.ts | 43 +- .../@angular/core/src/reflection/reflector.ts | 25 +- modules/@angular/core/src/render.ts | 2 +- modules/@angular/core/src/render/api.ts | 35 +- .../core/src/testability/testability.ts | 19 +- modules/@angular/core/src/util/decorators.ts | 30 +- modules/@angular/core/src/zone/ng_zone.ts | 7 +- .../@angular/core/src/zone/ng_zone_impl.ts | 2 +- .../active_animations_players_map_spec.ts | 31 +- .../animation/animation_group_player_spec.ts | 22 +- .../animation/animation_integration_spec.ts | 858 +++--- .../test/animation/animation_player_spec.ts | 22 +- .../animation_sequence_player_spec.ts | 22 +- .../animation/animation_style_util_spec.ts | 184 +- .../core/test/application_ref_spec.ts | 100 +- .../change_detector_util_spec.ts | 28 +- .../differs/default_iterable_differ_spec.ts | 331 +-- .../differs/default_keyvalue_differ_spec.ts | 87 +- .../differs/iterable_differs_spec.ts | 36 +- .../core/test/change_detection/util.ts | 21 +- .../core/test/debug/debug_node_spec.ts | 193 +- modules/@angular/core/test/dev_mode_spec.ts | 5 +- modules/@angular/core/test/di/binding_spec.ts | 21 +- .../@angular/core/test/di/forward_ref_spec.ts | 13 +- .../core/test/di/reflective_injector_spec.ts | 355 +-- .../core/test/di/reflective_key_spec.ts | 6 +- .../directive_lifecycle_integration_spec.ts | 83 +- .../core/test/dom/dom_adapter_spec.ts | 12 +- modules/@angular/core/test/dom/shim_spec.ts | 11 +- .../core/test/facade/observable_spec.ts | 36 +- modules/@angular/core/test/fake_async_spec.ts | 83 +- .../core/test/forward_ref_integration_spec.ts | 53 +- .../change_detection_integration_spec.ts | 312 +- .../linker/dynamic_component_loader_spec.ts | 257 +- .../core/test/linker/integration_spec.ts | 2616 +++++++++-------- .../linker/projection_integration_spec.ts | 1060 +++---- .../test/linker/query_integration_spec.ts | 758 +++-- .../core/test/linker/query_list_spec.ts | 37 +- .../reflector_component_resolver_spec.ts | 46 +- .../linker/regression_integration_spec.ts | 206 +- .../test/linker/security_integration_spec.ts | 241 +- .../linker/view_injector_integration_spec.ts | 296 +- modules/@angular/core/test/matchers_spec.ts | 16 +- .../core/test/metadata/decorators_spec.ts | 11 +- .../@angular/core/test/metadata/di_spec.ts | 136 +- .../core/test/reflection/reflector_common.ts | 6 +- .../core/test/reflection/reflector_spec.ts | 439 ++- modules/@angular/core/test/spies.ts | 4 +- .../core/test/testability/testability_spec.ts | 12 +- .../core/test/testing_internal_spec.ts | 65 +- .../core/test/util/decorators_spec.ts | 52 +- .../@angular/core/test/zone/ng_zone_spec.ts | 59 +- .../animation/mock_animation_driver.ts | 13 +- .../animation/mock_animation_player.ts | 2 +- modules/@angular/core/testing/async.ts | 10 +- modules/@angular/core/testing/fake_async.ts | 5 +- modules/@angular/core/testing/logger.ts | 2 +- .../core/testing/mock_application_ref.ts | 11 +- modules/@angular/core/testing/regexp.ts | 4 +- .../@angular/core/testing/test_injector.ts | 17 +- modules/@angular/core/testing/testing.ts | 13 +- .../@angular/core/testing/testing_internal.ts | 42 +- .../common/forms/ts/validators/validators.ts | 3 +- .../compiler/ts/url_resolver/url_resolver.ts | 2 +- .../animation/ts/dsl/animation_example.ts | 38 +- .../core/di/ts/forward_ref/forward_ref.ts | 15 +- .../forms/ts/ng_validators/ng_validators.ts | 2 +- .../pipes/ts/async_pipe/async_pipe_example.ts | 4 +- .../examples/core/ts/metadata/metadata.ts | 2 +- .../examples/core/ts/platform/platform.ts | 7 +- .../facade/ts/async/observable_patched.ts | 3 +- .../platform-browser/dom/debug/ts/by/by.ts | 2 +- .../debug_element_view_listener/providers.ts | 4 +- .../ts/can_activate/can_activate_example.ts | 9 +- .../ts/can_activate/can_activate_spec.ts | 2 +- .../can_deactivate/can_deactivate_example.ts | 13 +- .../ts/can_deactivate/can_deactivate_spec.ts | 2 +- .../ts/on_activate/on_activate_example.ts | 12 +- .../ts/on_deactivate/on_deactivate_example.ts | 14 +- .../ts/on_deactivate/on_deactivate_spec.ts | 2 +- .../ts/reuse/reuse_example.ts | 16 +- .../router_deprecated/ts/reuse/reuse_spec.ts | 2 +- .../examples/testing/ts/fake_async.ts | 3 +- .../@angular/examples/testing/ts/testing.ts | 26 +- modules/@angular/facade/src/async.ts | 33 +- modules/@angular/facade/src/collection.ts | 8 +- .../@angular/facade/src/exception_handler.ts | 12 +- modules/@angular/facade/src/exceptions.ts | 7 +- modules/@angular/facade/src/intl.ts | 44 +- modules/@angular/facade/src/lang.ts | 47 +- modules/@angular/facade/src/promise.ts | 13 +- modules/@angular/facade/test/async_spec.ts | 125 +- .../@angular/facade/test/collection_spec.ts | 38 +- .../facade/test/exception_handler_spec.ts | 90 +- modules/@angular/facade/test/lang_spec.ts | 79 +- modules/@angular/http/http.ts | 41 +- .../http/src/backends/jsonp_backend.ts | 22 +- .../@angular/http/src/backends/xhr_backend.ts | 21 +- .../@angular/http/src/base_request_options.ts | 31 +- .../http/src/base_response_options.ts | 9 +- modules/@angular/http/src/headers.ts | 19 +- modules/@angular/http/src/http.ts | 56 +- modules/@angular/http/src/http_utils.ts | 10 +- modules/@angular/http/src/interfaces.ts | 13 +- modules/@angular/http/src/static_request.ts | 14 +- modules/@angular/http/src/static_response.ts | 12 +- .../@angular/http/src/url_search_params.ts | 2 +- .../http/test/backends/jsonp_backend_spec.ts | 30 +- .../http/test/backends/mock_backend_spec.ts | 16 +- .../http/test/backends/xhr_backend_spec.ts | 242 +- .../http/test/base_request_options_spec.ts | 11 +- modules/@angular/http/test/headers_spec.ts | 16 +- modules/@angular/http/test/http_spec.ts | 89 +- .../http/test/static_response_spec.ts | 6 +- .../http/test/url_search_params_spec.ts | 35 +- modules/@angular/http/testing/mock_backend.ts | 23 +- .../platform-browser-dynamic/index.ts | 12 +- .../platform-browser-dynamic/testing.ts | 1 - .../platform-browser-dynamic/testing_e2e.ts | 3 +- .../@angular/platform-browser/core_private.ts | 3 +- modules/@angular/platform-browser/index.ts | 42 +- .../platform-browser/private_export.ts | 30 +- .../@angular/platform-browser/src/browser.ts | 119 +- .../src/browser/browser_adapter.ts | 126 +- .../src/browser/generic_browser_adapter.ts | 9 +- .../location/browser_platform_location.ts | 11 +- .../src/browser/location/history.ts | 2 +- .../src/browser/testability.ts | 18 +- .../src/browser/tools/common_tools.ts | 5 +- .../platform-browser/src/dom/debug/by.ts | 10 +- .../src/dom/debug/ng_probe.ts | 32 +- .../platform-browser/src/dom/dom_adapter.ts | 62 +- .../platform-browser/src/dom/dom_renderer.ts | 90 +- .../src/dom/events/event_manager.ts | 10 +- .../src/dom/events/hammer_common.ts | 3 +- .../src/dom/events/hammer_gestures.ts | 12 +- .../src/dom/events/key_events.ts | 16 +- .../@angular/platform-browser/src/dom/util.ts | 8 +- .../src/dom/web_animations_driver.ts | 45 +- .../src/dom/web_animations_player.ts | 11 +- .../src/security/dom_sanitization_service.ts | 5 +- .../src/security/html_sanitizer.ts | 42 +- .../src/security/url_sanitizer.ts | 3 +- .../shared/client_message_broker.ts | 34 +- .../src/web_workers/shared/message_bus.ts | 4 +- .../src/web_workers/shared/messaging_api.ts | 6 +- .../web_workers/shared/post_message_bus.ts | 19 +- .../web_workers/shared/serialized_types.ts | 7 +- .../src/web_workers/shared/serializer.ts | 27 +- .../shared/service_message_broker.ts | 20 +- .../src/web_workers/ui/event_dispatcher.ts | 155 +- .../src/web_workers/ui/event_serializer.ts | 31 +- .../src/web_workers/ui/location_providers.ts | 10 +- .../src/web_workers/ui/platform_location.ts | 36 +- .../src/web_workers/ui/renderer.ts | 169 +- .../web_workers/worker/event_deserializer.ts | 4 +- .../web_workers/worker/location_providers.ts | 19 +- .../web_workers/worker/platform_location.ts | 56 +- .../src/web_workers/worker/renderer.ts | 85 +- .../src/web_workers/worker/worker_adapter.ts | 280 +- .../platform-browser/src/worker_app.ts | 102 +- .../platform-browser/src/worker_render.ts | 158 +- .../platform-browser/src/xhr/xhr_impl.ts | 5 +- .../test/browser/bootstrap_spec.ts | 187 +- .../test/browser/browser_adapter_spec.ts | 14 +- .../test/browser/rectangle_mock.ts | 4 +- .../test/browser/title_spec.ts | 4 +- .../test/browser/tools/spies.ts | 5 +- .../test/browser/tools/tools_spec.ts | 14 +- .../test/browser_util_spec.ts | 5 +- .../test/dom/dom_renderer_integration_spec.ts | 11 +- .../test/dom/events/event_manager_spec.ts | 18 +- .../test/dom/events/key_events_spec.ts | 11 +- .../test/dom/shared_styles_host_spec.ts | 13 +- .../test/dom/web_animations_player_spec.ts | 48 +- .../test/security/html_sanitizer_spec.ts | 41 +- .../test/testing_public_browser_spec.ts | 65 +- .../test/testing_public_spec.ts | 101 +- .../web_workers/shared/message_bus_spec.ts | 78 +- .../web_workers/shared/message_bus_util.ts | 11 +- .../web_workers/shared/render_store_spec.ts | 11 +- .../shared/service_message_broker_spec.ts | 39 +- .../shared/web_worker_test_util.ts | 74 +- .../worker/platform_location_spec.ts | 79 +- .../worker/renderer_integration_spec.ts | 270 +- .../test/web_workers/worker/spies.ts | 5 +- .../test/xhr/xhr_cache_spec.ts | 48 +- .../test/xhr/xhr_impl_spec.ts | 18 +- .../testing/benchmark_util.ts | 6 +- .../platform-browser/testing/browser.ts | 29 +- .../testing/browser_static.ts | 37 +- .../platform-browser/testing/browser_util.ts | 20 +- .../testing/dom_test_component_renderer.ts | 9 +- .../platform-browser/testing/matchers.ts | 23 +- .../platform-browser/testing/perf_util.ts | 73 +- .../platform-server/src/parse5_adapter.ts | 570 ++-- .../platform-server/testing/server.ts | 53 +- modules/@angular/router-deprecated/router.ts | 9 +- .../src/directives/router_link.ts | 6 +- .../src/directives/router_outlet.ts | 30 +- .../router-deprecated/src/instruction.ts | 41 +- .../router-deprecated/src/interfaces.ts | 28 +- .../src/lifecycle/lifecycle_annotations.ts | 18 +- .../lifecycle/lifecycle_annotations_impl.ts | 10 +- .../lifecycle/route_lifecycle_reflector.ts | 6 +- .../route_config/route_config_decorator.ts | 6 +- .../route_config/route_config_normalizer.ts | 16 +- .../router-deprecated/src/route_definition.ts | 2 +- .../router-deprecated/src/route_registry.ts | 56 +- .../@angular/router-deprecated/src/router.ts | 152 +- .../router-deprecated/src/router_providers.ts | 6 +- .../src/router_providers_common.ts | 22 +- .../route_handlers/async_route_handler.ts | 5 +- .../route_handlers/sync_route_handler.ts | 5 +- .../src/rules/route_paths/param_route_path.ts | 21 +- .../src/rules/route_paths/regex_route_path.ts | 13 +- .../src/rules/route_paths/route_path.ts | 5 +- .../router-deprecated/src/rules/rule_set.ts | 28 +- .../router-deprecated/src/rules/rules.ts | 32 +- .../router-deprecated/src/url_parser.ts | 21 +- .../@angular/router-deprecated/src/utils.ts | 2 +- .../test/directives/router_link_spec.ts | 81 +- .../test/integration/async_route_spec.ts | 19 +- .../test/integration/auxiliary_route_spec.ts | 15 +- .../test/integration/bootstrap_spec.ts | 181 +- .../integration/impl/async_route_spec_impl.ts | 539 ++-- .../integration/impl/aux_route_spec_impl.ts | 204 +- .../integration/impl/fixture_components.ts | 19 +- .../integration/impl/sync_route_spec_impl.ts | 435 +-- .../test/integration/lifecycle_hook_spec.ts | 128 +- .../test/integration/navigation_spec.ts | 130 +- .../test/integration/redirect_route_spec.ts | 209 +- .../test/integration/router_link_spec.ts | 203 +- .../test/integration/sync_route_spec.ts | 17 +- .../test/integration/util.ts | 36 +- .../location/hash_location_strategy_spec.ts | 81 +- .../test/location/location_spec.ts | 22 +- .../location/path_location_strategy_spec.ts | 78 +- .../test/route_config/route_config_spec.ts | 199 +- .../test/route_registry_spec.ts | 251 +- .../router-deprecated/test/router_spec.ts | 80 +- .../route_paths/param_route_path_spec.ts | 10 +- .../route_paths/regex_route_param_spec.ts | 19 +- .../test/rules/rule_set_spec.ts | 167 +- .../@angular/router-deprecated/test/spies.ts | 2 +- .../router-deprecated/test/url_parser_spec.ts | 10 +- modules/@angular/router/index.ts | 15 +- modules/@angular/router/src/constants.ts | 2 +- .../src/directives/router_directives.ts | 4 +- .../router/src/directives/router_link.ts | 19 +- .../router/src/directives/router_outlet.ts | 26 +- modules/@angular/router/src/interfaces.ts | 7 +- .../router/src/lifecycle_reflector.ts | 2 +- modules/@angular/router/src/link.ts | 60 +- .../router/src/metadata/decorators.ts | 4 +- .../@angular/router/src/metadata/metadata.ts | 8 +- modules/@angular/router/src/recognize.ts | 145 +- modules/@angular/router/src/router.ts | 142 +- .../router/src/router_providers_common.ts | 20 +- .../router/src/router_url_serializer.ts | 20 +- modules/@angular/router/src/segments.ts | 27 +- .../@angular/router/test/integration_spec.ts | 436 +-- modules/@angular/router/test/link_spec.ts | 165 +- .../@angular/router/test/recognize_spec.ts | 288 +- .../@angular/router/test/router_link_spec.ts | 88 +- .../router/test/router_url_serializer_spec.ts | 94 +- modules/@angular/router/test/tree_spec.ts | 28 +- .../testing/router_testing_providers.ts | 26 +- modules/@angular/upgrade/src/angular_js.ts | 35 +- .../upgrade/src/downgrade_ng2_adapter.ts | 58 +- modules/@angular/upgrade/src/metadata.ts | 5 +- .../@angular/upgrade/src/upgrade_adapter.ts | 114 +- .../upgrade/src/upgrade_ng1_adapter.ts | 95 +- .../@angular/upgrade/test/metadata_spec.ts | 61 +- modules/@angular/upgrade/test/upgrade_spec.ts | 845 +++--- tools/public_api_guard/public_api_spec.ts | 4 +- 589 files changed, 21829 insertions(+), 24259 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 3172d20fe6..e23eede86d 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -9,7 +9,7 @@ require('./tools/check-environment')( const gulp = require('gulp'); const path = require('path'); -const srcsToFmt = ['tools/**/*.ts']; +const srcsToFmt = ['tools/**/*.ts', 'modules/@angular/**/*.ts']; gulp.task('format:enforce', () => { const format = require('gulp-clang-format'); diff --git a/modules/@angular/common/src/common_directives.ts b/modules/@angular/common/src/common_directives.ts index ebddb9b83d..d81dcd637c 100644 --- a/modules/@angular/common/src/common_directives.ts +++ b/modules/@angular/common/src/common_directives.ts @@ -1,6 +1,8 @@ import {Type} from '@angular/core'; -import {FORM_DIRECTIVES} from './forms-deprecated'; + import {CORE_DIRECTIVES} from './directives'; +import {FORM_DIRECTIVES} from './forms-deprecated'; + /** * A collection of Angular core directives that are likely to be used in each and every Angular diff --git a/modules/@angular/common/src/directives.ts b/modules/@angular/common/src/directives.ts index f0ddee00eb..c5af208965 100644 --- a/modules/@angular/common/src/directives.ts +++ b/modules/@angular/common/src/directives.ts @@ -3,11 +3,11 @@ * @description * Common directives shipped with Angular. */ +export {CORE_DIRECTIVES} from './directives/core_directives'; export {NgClass} from './directives/ng_class'; export {NgFor} from './directives/ng_for'; export {NgIf} from './directives/ng_if'; -export {NgTemplateOutlet} from './directives/ng_template_outlet'; +export {NgLocalization, NgPlural, NgPluralCase} from './directives/ng_plural'; export {NgStyle} from './directives/ng_style'; -export {NgSwitch, NgSwitchWhen, NgSwitchDefault} from './directives/ng_switch'; -export {NgPlural, NgPluralCase, NgLocalization} from './directives/ng_plural'; -export {CORE_DIRECTIVES} from './directives/core_directives'; +export {NgSwitch, NgSwitchDefault, NgSwitchWhen} from './directives/ng_switch'; +export {NgTemplateOutlet} from './directives/ng_template_outlet'; diff --git a/modules/@angular/common/src/directives/core_directives.ts b/modules/@angular/common/src/directives/core_directives.ts index cae92097b8..a40ea36785 100644 --- a/modules/@angular/common/src/directives/core_directives.ts +++ b/modules/@angular/common/src/directives/core_directives.ts @@ -1,11 +1,13 @@ import {Type} from '../facade/lang'; + import {NgClass} from './ng_class'; import {NgFor} from './ng_for'; import {NgIf} from './ng_if'; -import {NgTemplateOutlet} from './ng_template_outlet'; -import {NgStyle} from './ng_style'; -import {NgSwitch, NgSwitchWhen, NgSwitchDefault} from './ng_switch'; import {NgPlural, NgPluralCase} from './ng_plural'; +import {NgStyle} from './ng_style'; +import {NgSwitch, NgSwitchDefault, NgSwitchWhen} from './ng_switch'; +import {NgTemplateOutlet} from './ng_template_outlet'; + /** * A collection of Angular core directives that are likely to be used in each and every Angular @@ -59,5 +61,5 @@ export const CORE_DIRECTIVES: Type[] = /*@ts2dart_const*/[ NgSwitchWhen, NgSwitchDefault, NgPlural, - NgPluralCase + NgPluralCase, ]; diff --git a/modules/@angular/common/src/directives/ng_class.ts b/modules/@angular/common/src/directives/ng_class.ts index 7f546bb24c..f5c09ffe15 100644 --- a/modules/@angular/common/src/directives/ng_class.ts +++ b/modules/@angular/common/src/directives/ng_class.ts @@ -1,18 +1,8 @@ -import { - DoCheck, - OnDestroy, - Directive, - ElementRef, - IterableDiffers, - KeyValueDiffers, - Renderer, - IterableDiffer, - KeyValueDiffer, - CollectionChangeRecord, - KeyValueChangeRecord -} from '@angular/core'; -import {isPresent, isString, isArray} from '../facade/lang'; +import {CollectionChangeRecord, Directive, DoCheck, ElementRef, IterableDiffer, IterableDiffers, KeyValueChangeRecord, KeyValueDiffer, KeyValueDiffers, OnDestroy, Renderer} from '@angular/core'; + import {StringMapWrapper, isListLikeIterable} from '../facade/collection'; +import {isArray, isPresent, isString} from '../facade/lang'; + /** * The `NgClass` directive conditionally adds and removes CSS classes on an HTML element based on @@ -80,10 +70,11 @@ export class NgClass implements DoCheck, OnDestroy { private _iterableDiffer: IterableDiffer; private _keyValueDiffer: KeyValueDiffer; private _initialClasses: string[] = []; - private _rawClass: string[] | Set; + private _rawClass: string[]|Set; - constructor(private _iterableDiffers: IterableDiffers, private _keyValueDiffers: KeyValueDiffers, - private _ngEl: ElementRef, private _renderer: Renderer) {} + constructor( + private _iterableDiffers: IterableDiffers, private _keyValueDiffers: KeyValueDiffers, + private _ngEl: ElementRef, private _renderer: Renderer) {} set initialClasses(v: string) { this._applyInitialClasses(true); @@ -92,14 +83,14 @@ export class NgClass implements DoCheck, OnDestroy { this._applyClasses(this._rawClass, false); } - set rawClass(v: string | string[] | Set| {[key: string]: any}) { + set rawClass(v: string|string[]|Set|{[key: string]: any}) { this._cleanupClasses(this._rawClass); if (isString(v)) { v = (v).split(' '); } - this._rawClass = >v; + this._rawClass = >v; this._iterableDiffer = null; this._keyValueDiffer = null; if (isPresent(v)) { @@ -128,7 +119,7 @@ export class NgClass implements DoCheck, OnDestroy { ngOnDestroy(): void { this._cleanupClasses(this._rawClass); } - private _cleanupClasses(rawClassVal: string[] | Set| {[key: string]: any}): void { + private _cleanupClasses(rawClassVal: string[]|Set|{[key: string]: any}): void { this._applyClasses(rawClassVal, true); this._applyInitialClasses(false); } @@ -156,18 +147,18 @@ export class NgClass implements DoCheck, OnDestroy { this._initialClasses.forEach(className => this._toggleClass(className, !isCleanup)); } - private _applyClasses(rawClassVal: string[] | Set| {[key: string]: any}, - isCleanup: boolean) { + private _applyClasses( + rawClassVal: string[]|Set|{[key: string]: any}, isCleanup: boolean) { if (isPresent(rawClassVal)) { if (isArray(rawClassVal)) { (rawClassVal).forEach(className => this._toggleClass(className, !isCleanup)); } else if (rawClassVal instanceof Set) { (>rawClassVal).forEach(className => this._toggleClass(className, !isCleanup)); } else { - StringMapWrapper.forEach(<{[k: string]: any}>rawClassVal, - (expVal: any, className: string) => { - if (isPresent(expVal)) this._toggleClass(className, !isCleanup); - }); + StringMapWrapper.forEach( + <{[k: string]: any}>rawClassVal, (expVal: any, className: string) => { + if (isPresent(expVal)) this._toggleClass(className, !isCleanup); + }); } } } diff --git a/modules/@angular/common/src/directives/ng_for.ts b/modules/@angular/common/src/directives/ng_for.ts index 6afd39330a..fa0e7dfdde 100644 --- a/modules/@angular/common/src/directives/ng_for.ts +++ b/modules/@angular/common/src/directives/ng_for.ts @@ -1,18 +1,7 @@ -import { - DoCheck, - Directive, - ChangeDetectorRef, - IterableDiffer, - IterableDiffers, - ViewContainerRef, - TemplateRef, - EmbeddedViewRef, - TrackByFn, - DefaultIterableDiffer, - CollectionChangeRecord -} from '@angular/core'; -import {isPresent, isBlank, getTypeNameForDebugging} from '../facade/lang'; +import {ChangeDetectorRef, CollectionChangeRecord, DefaultIterableDiffer, Directive, DoCheck, EmbeddedViewRef, IterableDiffer, IterableDiffers, TemplateRef, TrackByFn, ViewContainerRef} from '@angular/core'; + import {BaseException} from '../facade/exceptions'; +import {getTypeNameForDebugging, isBlank, isPresent} from '../facade/lang'; export class NgForRow { constructor(public $implicit: any, public index: number, public count: number) {} @@ -87,8 +76,9 @@ export class NgFor implements DoCheck { _ngForTrackBy: TrackByFn; private _differ: IterableDiffer; - constructor(private _viewContainer: ViewContainerRef, private _templateRef: TemplateRef, - private _iterableDiffers: IterableDiffers, private _cdr: ChangeDetectorRef) {} + constructor( + private _viewContainer: ViewContainerRef, private _templateRef: TemplateRef, + private _iterableDiffers: IterableDiffers, private _cdr: ChangeDetectorRef) {} set ngForOf(value: any) { this._ngForOf = value; @@ -121,16 +111,19 @@ export class NgFor implements DoCheck { // TODO(rado): check if change detection can produce a change record that is // easier to consume than current. var recordViewTuples: RecordViewTuple[] = []; - changes.forEachRemovedItem((removedRecord: CollectionChangeRecord) => - recordViewTuples.push(new RecordViewTuple(removedRecord, null))); + changes.forEachRemovedItem( + (removedRecord: CollectionChangeRecord) => + recordViewTuples.push(new RecordViewTuple(removedRecord, null))); - changes.forEachMovedItem((movedRecord: CollectionChangeRecord) => - recordViewTuples.push(new RecordViewTuple(movedRecord, null))); + changes.forEachMovedItem( + (movedRecord: CollectionChangeRecord) => + recordViewTuples.push(new RecordViewTuple(movedRecord, null))); var insertTuples = this._bulkRemove(recordViewTuples); - changes.forEachAddedItem((addedRecord: CollectionChangeRecord) => - insertTuples.push(new RecordViewTuple(addedRecord, null))); + changes.forEachAddedItem( + (addedRecord: CollectionChangeRecord) => + insertTuples.push(new RecordViewTuple(addedRecord, null))); this._bulkInsert(insertTuples); @@ -155,8 +148,9 @@ export class NgFor implements DoCheck { } private _bulkRemove(tuples: RecordViewTuple[]): RecordViewTuple[] { - tuples.sort((a: RecordViewTuple, b: RecordViewTuple) => - a.record.previousIndex - b.record.previousIndex); + tuples.sort( + (a: RecordViewTuple, b: RecordViewTuple) => + a.record.previousIndex - b.record.previousIndex); var movedTuples: RecordViewTuple[] = []; for (var i = tuples.length - 1; i >= 0; i--) { var tuple = tuples[i]; diff --git a/modules/@angular/common/src/directives/ng_if.ts b/modules/@angular/common/src/directives/ng_if.ts index 27cc9f7339..3072e8b224 100644 --- a/modules/@angular/common/src/directives/ng_if.ts +++ b/modules/@angular/common/src/directives/ng_if.ts @@ -1,6 +1,8 @@ -import {Directive, ViewContainerRef, TemplateRef} from '@angular/core'; +import {Directive, TemplateRef, ViewContainerRef} from '@angular/core'; + import {isBlank} from '../facade/lang'; + /** * Removes or recreates a portion of the DOM tree based on an {expression}. * diff --git a/modules/@angular/common/src/directives/ng_plural.ts b/modules/@angular/common/src/directives/ng_plural.ts index d5116f3cce..073d528d91 100644 --- a/modules/@angular/common/src/directives/ng_plural.ts +++ b/modules/@angular/common/src/directives/ng_plural.ts @@ -1,15 +1,7 @@ -import { - Directive, - ViewContainerRef, - TemplateRef, - ContentChildren, - QueryList, - Attribute, - AfterContentInit, - Input -} from '@angular/core'; -import {isPresent, NumberWrapper} from '../facade/lang'; +import {AfterContentInit, Attribute, ContentChildren, Directive, Input, QueryList, TemplateRef, ViewContainerRef} from '@angular/core'; + import {Map} from '../facade/collection'; +import {NumberWrapper, isPresent} from '../facade/lang'; import {SwitchView} from './ng_switch'; @@ -81,8 +73,9 @@ export abstract class NgLocalization { abstract getPluralCategory(value: any): s export class NgPluralCase { /** @internal */ _view: SwitchView; - constructor(@Attribute('ngPluralCase') public value: string, template: TemplateRef, - viewContainer: ViewContainerRef) { + constructor( + @Attribute('ngPluralCase') public value: string, template: TemplateRef, + viewContainer: ViewContainerRef) { this._view = new SwitchView(viewContainer, template); } } @@ -143,7 +136,7 @@ export class NgPlural implements AfterContentInit { } /** @internal */ - _isValueView(pluralCase: NgPluralCase): boolean { return pluralCase.value[0] === "="; } + _isValueView(pluralCase: NgPluralCase): boolean { return pluralCase.value[0] === '='; } /** @internal */ _formatValue(pluralCase: NgPluralCase): any { diff --git a/modules/@angular/common/src/directives/ng_style.ts b/modules/@angular/common/src/directives/ng_style.ts index b920173d0e..f5f4606490 100644 --- a/modules/@angular/common/src/directives/ng_style.ts +++ b/modules/@angular/common/src/directives/ng_style.ts @@ -1,13 +1,7 @@ -import { - DoCheck, - KeyValueChangeRecord, - KeyValueDiffer, - KeyValueDiffers, - ElementRef, - Directive, - Renderer -} from '@angular/core'; -import {isPresent, isBlank} from '../facade/lang'; +import {Directive, DoCheck, ElementRef, KeyValueChangeRecord, KeyValueDiffer, KeyValueDiffers, Renderer} from '@angular/core'; + +import {isBlank, isPresent} from '../facade/lang'; + /** * The `NgStyle` directive changes styles based on a result of expression evaluation. @@ -69,8 +63,8 @@ export class NgStyle implements DoCheck { /** @internal */ _differ: KeyValueDiffer; - constructor(private _differs: KeyValueDiffers, private _ngEl: ElementRef, - private _renderer: Renderer) {} + constructor( + private _differs: KeyValueDiffers, private _ngEl: ElementRef, private _renderer: Renderer) {} set rawStyle(v: {[key: string]: string}) { this._rawStyle = v; diff --git a/modules/@angular/common/src/directives/ng_switch.ts b/modules/@angular/common/src/directives/ng_switch.ts index f822f3d124..0b2ae7cead 100644 --- a/modules/@angular/common/src/directives/ng_switch.ts +++ b/modules/@angular/common/src/directives/ng_switch.ts @@ -1,12 +1,13 @@ -import {Directive, Host, ViewContainerRef, TemplateRef} from '@angular/core'; -import {isPresent, isBlank, normalizeBlank} from '../facade/lang'; +import {Directive, Host, TemplateRef, ViewContainerRef} from '@angular/core'; + import {ListWrapper, Map} from '../facade/collection'; +import {isBlank, isPresent, normalizeBlank} from '../facade/lang'; const _WHEN_DEFAULT = /*@ts2dart_const*/ new Object(); export class SwitchView { - constructor(private _viewContainerRef: ViewContainerRef, - private _templateRef: TemplateRef) {} + constructor( + private _viewContainerRef: ViewContainerRef, private _templateRef: TemplateRef) {} create(): void { this._viewContainerRef.createEmbeddedView(this._templateRef); } @@ -180,8 +181,9 @@ export class NgSwitchWhen { _view: SwitchView; private _switch: NgSwitch; - constructor(viewContainer: ViewContainerRef, templateRef: TemplateRef, - @Host() ngSwitch: NgSwitch) { + constructor( + viewContainer: ViewContainerRef, templateRef: TemplateRef, + @Host() ngSwitch: NgSwitch) { this._switch = ngSwitch; this._view = new SwitchView(viewContainer, templateRef); } @@ -202,8 +204,9 @@ export class NgSwitchWhen { */ @Directive({selector: '[ngSwitchDefault]'}) export class NgSwitchDefault { - constructor(viewContainer: ViewContainerRef, templateRef: TemplateRef, - @Host() sswitch: NgSwitch) { + constructor( + viewContainer: ViewContainerRef, templateRef: TemplateRef, + @Host() sswitch: NgSwitch) { sswitch._registerView(_WHEN_DEFAULT, new SwitchView(viewContainer, templateRef)); } } diff --git a/modules/@angular/common/src/directives/ng_template_outlet.ts b/modules/@angular/common/src/directives/ng_template_outlet.ts index 7135ec3661..d72facdc9b 100644 --- a/modules/@angular/common/src/directives/ng_template_outlet.ts +++ b/modules/@angular/common/src/directives/ng_template_outlet.ts @@ -1,6 +1,8 @@ -import {Directive, Input, ViewContainerRef, ViewRef, TemplateRef} from '@angular/core'; +import {Directive, Input, TemplateRef, ViewContainerRef, ViewRef} from '@angular/core'; + import {isPresent} from '../facade/lang'; + /** * Creates and inserts an embedded view based on a prepared `TemplateRef`. * diff --git a/modules/@angular/common/src/forms-deprecated.ts b/modules/@angular/common/src/forms-deprecated.ts index 70dffe5efa..4c597e51ad 100644 --- a/modules/@angular/common/src/forms-deprecated.ts +++ b/modules/@angular/common/src/forms-deprecated.ts @@ -10,39 +10,32 @@ * Forms providers are not included in default providers; you must import these providers * explicitly. */ -export {AbstractControl, Control, ControlGroup, ControlArray} from './forms-deprecated/model'; +import {Type} from '@angular/core'; +import {RadioControlRegistry} from './forms-deprecated/directives/radio_control_value_accessor'; +import {FormBuilder} from './forms-deprecated/form_builder'; + +export {FORM_DIRECTIVES, RadioButtonState} from './forms-deprecated/directives'; export {AbstractControlDirective} from './forms-deprecated/directives/abstract_control_directive'; -export {Form} from './forms-deprecated/directives/form_interface'; +export {CheckboxControlValueAccessor} from './forms-deprecated/directives/checkbox_value_accessor'; export {ControlContainer} from './forms-deprecated/directives/control_container'; -export {NgControlName} from './forms-deprecated/directives/ng_control_name'; -export {NgFormControl} from './forms-deprecated/directives/ng_form_control'; -export {NgModel} from './forms-deprecated/directives/ng_model'; -export {NgControl} from './forms-deprecated/directives/ng_control'; -export {NgControlGroup} from './forms-deprecated/directives/ng_control_group'; -export {NgFormModel} from './forms-deprecated/directives/ng_form_model'; -export {NgForm} from './forms-deprecated/directives/ng_form'; export {ControlValueAccessor, NG_VALUE_ACCESSOR} from './forms-deprecated/directives/control_value_accessor'; export {DefaultValueAccessor} from './forms-deprecated/directives/default_value_accessor'; +export {Form} from './forms-deprecated/directives/form_interface'; +export {NgControl} from './forms-deprecated/directives/ng_control'; +export {NgControlGroup} from './forms-deprecated/directives/ng_control_group'; +export {NgControlName} from './forms-deprecated/directives/ng_control_name'; export {NgControlStatus} from './forms-deprecated/directives/ng_control_status'; -export {CheckboxControlValueAccessor} from './forms-deprecated/directives/checkbox_value_accessor'; -export { - NgSelectOption, - SelectControlValueAccessor -} from './forms-deprecated/directives/select_control_value_accessor'; -export {FORM_DIRECTIVES, RadioButtonState} from './forms-deprecated/directives'; -export {NG_VALIDATORS, NG_ASYNC_VALIDATORS, Validators} from './forms-deprecated/validators'; -export { - RequiredValidator, - MinLengthValidator, - MaxLengthValidator, - PatternValidator, - Validator -} from './forms-deprecated/directives/validators'; +export {NgForm} from './forms-deprecated/directives/ng_form'; +export {NgFormControl} from './forms-deprecated/directives/ng_form_control'; +export {NgFormModel} from './forms-deprecated/directives/ng_form_model'; +export {NgModel} from './forms-deprecated/directives/ng_model'; +export {NgSelectOption, SelectControlValueAccessor} from './forms-deprecated/directives/select_control_value_accessor'; +export {MaxLengthValidator, MinLengthValidator, PatternValidator, RequiredValidator, Validator} from './forms-deprecated/directives/validators'; export {FormBuilder} from './forms-deprecated/form_builder'; -import {FormBuilder} from './forms-deprecated/form_builder'; -import {RadioControlRegistry} from './forms-deprecated/directives/radio_control_value_accessor'; -import {Type} from '@angular/core'; +export {AbstractControl, Control, ControlArray, ControlGroup} from './forms-deprecated/model'; +export {NG_ASYNC_VALIDATORS, NG_VALIDATORS, Validators} from './forms-deprecated/validators'; + /** * Shorthand set of providers used for building Angular forms. diff --git a/modules/@angular/common/src/forms-deprecated/directives.ts b/modules/@angular/common/src/forms-deprecated/directives.ts index 6f370f5796..6a3b4c61d4 100644 --- a/modules/@angular/common/src/forms-deprecated/directives.ts +++ b/modules/@angular/common/src/forms-deprecated/directives.ts @@ -1,60 +1,37 @@ import {Type} from '@angular/core'; -import {NgControlName} from './directives/ng_control_name'; -import {NgFormControl} from './directives/ng_form_control'; -import {NgModel} from './directives/ng_model'; -import {NgControlGroup} from './directives/ng_control_group'; -import {NgFormModel} from './directives/ng_form_model'; -import {NgForm} from './directives/ng_form'; -import {DefaultValueAccessor} from './directives/default_value_accessor'; + import {CheckboxControlValueAccessor} from './directives/checkbox_value_accessor'; +import {DefaultValueAccessor} from './directives/default_value_accessor'; +import {NgControlGroup} from './directives/ng_control_group'; +import {NgControlName} from './directives/ng_control_name'; +import {NgControlStatus} from './directives/ng_control_status'; +import {NgForm} from './directives/ng_form'; +import {NgFormControl} from './directives/ng_form_control'; +import {NgFormModel} from './directives/ng_form_model'; +import {NgModel} from './directives/ng_model'; import {NumberValueAccessor} from './directives/number_value_accessor'; import {RadioControlValueAccessor} from './directives/radio_control_value_accessor'; -import {NgControlStatus} from './directives/ng_control_status'; -import { - SelectControlValueAccessor, - NgSelectOption -} from './directives/select_control_value_accessor'; -import { - SelectMultipleControlValueAccessor, - NgSelectMultipleOption -} from './directives/select_multiple_control_value_accessor'; -import { - RequiredValidator, - MinLengthValidator, - MaxLengthValidator, - PatternValidator -} from './directives/validators'; +import {NgSelectOption, SelectControlValueAccessor} from './directives/select_control_value_accessor'; +import {NgSelectMultipleOption, SelectMultipleControlValueAccessor} from './directives/select_multiple_control_value_accessor'; +import {MaxLengthValidator, MinLengthValidator, PatternValidator, RequiredValidator} from './directives/validators'; -export {NgControlName} from './directives/ng_control_name'; -export {NgFormControl} from './directives/ng_form_control'; -export {NgModel} from './directives/ng_model'; -export {NgControlGroup} from './directives/ng_control_group'; -export {NgFormModel} from './directives/ng_form_model'; -export {NgForm} from './directives/ng_form'; -export {DefaultValueAccessor} from './directives/default_value_accessor'; export {CheckboxControlValueAccessor} from './directives/checkbox_value_accessor'; -export { - RadioControlValueAccessor, - RadioButtonState -} from './directives/radio_control_value_accessor'; -export {NumberValueAccessor} from './directives/number_value_accessor'; -export {NgControlStatus} from './directives/ng_control_status'; -export { - SelectControlValueAccessor, - NgSelectOption -} from './directives/select_control_value_accessor'; -export { - SelectMultipleControlValueAccessor, - NgSelectMultipleOption -} from './directives/select_multiple_control_value_accessor'; -export { - RequiredValidator, - MinLengthValidator, - MaxLengthValidator, - PatternValidator -} from './directives/validators'; -export {NgControl} from './directives/ng_control'; export {ControlValueAccessor} from './directives/control_value_accessor'; +export {DefaultValueAccessor} from './directives/default_value_accessor'; +export {NgControl} from './directives/ng_control'; +export {NgControlGroup} from './directives/ng_control_group'; +export {NgControlName} from './directives/ng_control_name'; +export {NgControlStatus} from './directives/ng_control_status'; +export {NgForm} from './directives/ng_form'; +export {NgFormControl} from './directives/ng_form_control'; +export {NgFormModel} from './directives/ng_form_model'; +export {NgModel} from './directives/ng_model'; +export {NumberValueAccessor} from './directives/number_value_accessor'; +export {RadioButtonState, RadioControlValueAccessor} from './directives/radio_control_value_accessor'; +export {NgSelectOption, SelectControlValueAccessor} from './directives/select_control_value_accessor'; +export {NgSelectMultipleOption, SelectMultipleControlValueAccessor} from './directives/select_multiple_control_value_accessor'; +export {MaxLengthValidator, MinLengthValidator, PatternValidator, RequiredValidator} from './directives/validators'; + /** * @@ -95,5 +72,5 @@ export const FORM_DIRECTIVES: Type[] = /*@ts2dart_const*/[ RequiredValidator, MinLengthValidator, MaxLengthValidator, - PatternValidator + PatternValidator, ]; diff --git a/modules/@angular/common/src/forms-deprecated/directives/abstract_control_directive.ts b/modules/@angular/common/src/forms-deprecated/directives/abstract_control_directive.ts index 584d1cb976..19155a3551 100644 --- a/modules/@angular/common/src/forms-deprecated/directives/abstract_control_directive.ts +++ b/modules/@angular/common/src/forms-deprecated/directives/abstract_control_directive.ts @@ -1,6 +1,7 @@ -import {AbstractControl} from '../model'; -import {isPresent} from '../../facade/lang'; import {unimplemented} from '../../facade/exceptions'; +import {isPresent} from '../../facade/lang'; +import {AbstractControl} from '../model'; + /** * Base class for control directives. diff --git a/modules/@angular/common/src/forms-deprecated/directives/checkbox_value_accessor.ts b/modules/@angular/common/src/forms-deprecated/directives/checkbox_value_accessor.ts index 15a1c9b238..0c37fda55b 100644 --- a/modules/@angular/common/src/forms-deprecated/directives/checkbox_value_accessor.ts +++ b/modules/@angular/common/src/forms-deprecated/directives/checkbox_value_accessor.ts @@ -1,5 +1,6 @@ -import {Directive, Renderer, ElementRef, forwardRef} from '@angular/core'; -import {NG_VALUE_ACCESSOR, ControlValueAccessor} from './control_value_accessor'; +import {Directive, ElementRef, Renderer, forwardRef} from '@angular/core'; + +import {ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor'; export const CHECKBOX_VALUE_ACCESSOR: any = /*@ts2dart_const*/ { provide: NG_VALUE_ACCESSOR, diff --git a/modules/@angular/common/src/forms-deprecated/directives/control_container.ts b/modules/@angular/common/src/forms-deprecated/directives/control_container.ts index e321b51aa8..23ce459784 100644 --- a/modules/@angular/common/src/forms-deprecated/directives/control_container.ts +++ b/modules/@angular/common/src/forms-deprecated/directives/control_container.ts @@ -1,5 +1,6 @@ -import {Form} from './form_interface'; import {AbstractControlDirective} from './abstract_control_directive'; +import {Form} from './form_interface'; + /** * A directive that contains multiple {@link NgControl}s. diff --git a/modules/@angular/common/src/forms-deprecated/directives/control_value_accessor.ts b/modules/@angular/common/src/forms-deprecated/directives/control_value_accessor.ts index f080268e77..2ea1adfdc9 100644 --- a/modules/@angular/common/src/forms-deprecated/directives/control_value_accessor.ts +++ b/modules/@angular/common/src/forms-deprecated/directives/control_value_accessor.ts @@ -34,4 +34,4 @@ export interface ControlValueAccessor { * @experimental */ export const NG_VALUE_ACCESSOR: OpaqueToken = - /*@ts2dart_const*/ new OpaqueToken("NgValueAccessor"); + /*@ts2dart_const*/ new OpaqueToken('NgValueAccessor'); diff --git a/modules/@angular/common/src/forms-deprecated/directives/default_value_accessor.ts b/modules/@angular/common/src/forms-deprecated/directives/default_value_accessor.ts index e8a962cc66..fa7bef3587 100644 --- a/modules/@angular/common/src/forms-deprecated/directives/default_value_accessor.ts +++ b/modules/@angular/common/src/forms-deprecated/directives/default_value_accessor.ts @@ -1,6 +1,8 @@ import {Directive, ElementRef, Renderer, forwardRef} from '@angular/core'; + import {isBlank} from '../../facade/lang'; -import {NG_VALUE_ACCESSOR, ControlValueAccessor} from './control_value_accessor'; + +import {ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor'; export const DEFAULT_VALUE_ACCESSOR: any = /*@ts2dart_const*/ /* @ts2dart_Provider */ { diff --git a/modules/@angular/common/src/forms-deprecated/directives/form_interface.ts b/modules/@angular/common/src/forms-deprecated/directives/form_interface.ts index f1092f46b2..fe16d01627 100644 --- a/modules/@angular/common/src/forms-deprecated/directives/form_interface.ts +++ b/modules/@angular/common/src/forms-deprecated/directives/form_interface.ts @@ -1,6 +1,8 @@ +import {Control, ControlGroup} from '../model'; + import {NgControl} from './ng_control'; import {NgControlGroup} from './ng_control_group'; -import {Control, ControlGroup} from '../model'; + /** * An interface that {@link NgFormModel} and {@link NgForm} implement. diff --git a/modules/@angular/common/src/forms-deprecated/directives/ng_control.ts b/modules/@angular/common/src/forms-deprecated/directives/ng_control.ts index f96af30570..e9d237b307 100644 --- a/modules/@angular/common/src/forms-deprecated/directives/ng_control.ts +++ b/modules/@angular/common/src/forms-deprecated/directives/ng_control.ts @@ -1,9 +1,10 @@ import {unimplemented} from '../../facade/exceptions'; -import {ControlValueAccessor} from './control_value_accessor'; import {AbstractControlDirective} from './abstract_control_directive'; +import {ControlValueAccessor} from './control_value_accessor'; import {AsyncValidatorFn, ValidatorFn} from './validators'; + /** * A base class that all control directive extend. * It binds a {@link Control} object to a DOM element. diff --git a/modules/@angular/common/src/forms-deprecated/directives/ng_control_group.ts b/modules/@angular/common/src/forms-deprecated/directives/ng_control_group.ts index 5b80b72555..9a5fcdbf8c 100644 --- a/modules/@angular/common/src/forms-deprecated/directives/ng_control_group.ts +++ b/modules/@angular/common/src/forms-deprecated/directives/ng_control_group.ts @@ -1,19 +1,11 @@ -import { - OnInit, - OnDestroy, - Directive, - Optional, - Inject, - Host, - SkipSelf, - forwardRef, - Self -} from '@angular/core'; -import {ControlContainer} from './control_container'; -import {controlPath, composeValidators, composeAsyncValidators} from './shared'; +import {Directive, Host, Inject, OnDestroy, OnInit, Optional, Self, SkipSelf, forwardRef} from '@angular/core'; + import {ControlGroup} from '../model'; +import {NG_ASYNC_VALIDATORS, NG_VALIDATORS} from '../validators'; + +import {ControlContainer} from './control_container'; import {Form} from './form_interface'; -import {NG_VALIDATORS, NG_ASYNC_VALIDATORS} from '../validators'; +import {composeAsyncValidators, composeValidators, controlPath} from './shared'; import {AsyncValidatorFn, ValidatorFn} from './validators'; export const controlGroupProvider: any = @@ -79,9 +71,10 @@ export class NgControlGroup extends ControlContainer implements OnInit, /** @internal */ _parent: ControlContainer; - constructor(@Host() @SkipSelf() parent: ControlContainer, - @Optional() @Self() @Inject(NG_VALIDATORS) private _validators: any[], - @Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: any[]) { + constructor( + @Host() @SkipSelf() parent: ControlContainer, + @Optional() @Self() @Inject(NG_VALIDATORS) private _validators: any[], + @Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: any[]) { super(); this._parent = parent; } diff --git a/modules/@angular/common/src/forms-deprecated/directives/ng_control_name.ts b/modules/@angular/common/src/forms-deprecated/directives/ng_control_name.ts index 48a481bc2b..a59f145bd3 100644 --- a/modules/@angular/common/src/forms-deprecated/directives/ng_control_name.ts +++ b/modules/@angular/common/src/forms-deprecated/directives/ng_control_name.ts @@ -1,30 +1,14 @@ -import { - OnChanges, - OnDestroy, - SimpleChanges, - Directive, - forwardRef, - Host, - SkipSelf, - Inject, - Optional, - Self -} from '@angular/core'; +import {Directive, Host, Inject, OnChanges, OnDestroy, Optional, Self, SimpleChanges, SkipSelf, forwardRef} from '@angular/core'; import {EventEmitter, ObservableWrapper} from '../../facade/async'; -import {ControlContainer} from './control_container'; -import {NgControl} from './ng_control'; -import {ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor'; -import { - controlPath, - composeValidators, - composeAsyncValidators, - isPropertyUpdated, - selectValueAccessor -} from './shared'; import {Control} from '../model'; -import {NG_VALIDATORS, NG_ASYNC_VALIDATORS} from '../validators'; -import {ValidatorFn, AsyncValidatorFn} from './validators'; +import {NG_ASYNC_VALIDATORS, NG_VALIDATORS} from '../validators'; + +import {ControlContainer} from './control_container'; +import {ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor'; +import {NgControl} from './ng_control'; +import {composeAsyncValidators, composeValidators, controlPath, isPropertyUpdated, selectValueAccessor} from './shared'; +import {AsyncValidatorFn, ValidatorFn} from './validators'; export const controlNameBinding: any = @@ -112,35 +96,37 @@ export class NgControlName extends NgControl implements OnChanges, /* Array */ any[], @Optional() @Self() @Inject(NG_VALUE_ACCESSOR) valueAccessors: ControlValueAccessor[]) { - super(); - this.valueAccessor = selectValueAccessor(this, valueAccessors); - } + super(); + this.valueAccessor = selectValueAccessor(this, valueAccessors); + } - ngOnChanges(changes: SimpleChanges) { - if (!this._added) { - this.formDirective.addControl(this); - this._added = true; - } - if (isPropertyUpdated(changes, this.viewModel)) { - this.viewModel = this.model; - this.formDirective.updateModel(this, this.model); - } - } + ngOnChanges(changes: SimpleChanges) { + if (!this._added) { + this.formDirective.addControl(this); + this._added = true; + } + if (isPropertyUpdated(changes, this.viewModel)) { + this.viewModel = this.model; + this.formDirective.updateModel(this, this.model); + } + } - ngOnDestroy(): void { this.formDirective.removeControl(this); } + ngOnDestroy(): void { this.formDirective.removeControl(this); } - viewToModelUpdate(newValue: any): void { - this.viewModel = newValue; - ObservableWrapper.callEmit(this.update, newValue); - } + viewToModelUpdate(newValue: any): void { + this.viewModel = newValue; + ObservableWrapper.callEmit(this.update, newValue); + } - get path(): string[] { return controlPath(this.name, this._parent); } + get path(): string[] { return controlPath(this.name, this._parent); } - get formDirective(): any { return this._parent.formDirective; } + get formDirective(): any { return this._parent.formDirective; } - get validator(): ValidatorFn { return composeValidators(this._validators); } + get validator(): ValidatorFn { return composeValidators(this._validators); } - get asyncValidator(): AsyncValidatorFn { return composeAsyncValidators(this._asyncValidators); } + get asyncValidator(): AsyncValidatorFn { + return composeAsyncValidators(this._asyncValidators); + } - get control(): Control { return this.formDirective.getControl(this); } + get control(): Control { return this.formDirective.getControl(this); } } diff --git a/modules/@angular/common/src/forms-deprecated/directives/ng_control_status.ts b/modules/@angular/common/src/forms-deprecated/directives/ng_control_status.ts index 5f29cc6adb..2b1b1a323c 100644 --- a/modules/@angular/common/src/forms-deprecated/directives/ng_control_status.ts +++ b/modules/@angular/common/src/forms-deprecated/directives/ng_control_status.ts @@ -1,7 +1,10 @@ import {Directive, Self} from '@angular/core'; -import {NgControl} from './ng_control'; + import {isPresent} from '../../facade/lang'; +import {NgControl} from './ng_control'; + + /** * Directive automatically applied to Angular forms that sets CSS classes * based on control status (valid/invalid/dirty/etc). diff --git a/modules/@angular/common/src/forms-deprecated/directives/ng_form.ts b/modules/@angular/common/src/forms-deprecated/directives/ng_form.ts index dfd20788c7..71f2773f7f 100644 --- a/modules/@angular/common/src/forms-deprecated/directives/ng_form.ts +++ b/modules/@angular/common/src/forms-deprecated/directives/ng_form.ts @@ -1,18 +1,16 @@ -import {Directive, forwardRef, Optional, Inject, Self} from '@angular/core'; -import { - PromiseWrapper, - ObservableWrapper, - EventEmitter -} from '../../facade/async'; +import {Directive, Inject, Optional, Self, forwardRef} from '@angular/core'; + +import {EventEmitter, ObservableWrapper, PromiseWrapper} from '../../facade/async'; import {ListWrapper} from '../../facade/collection'; import {isPresent} from '../../facade/lang'; -import {NgControl} from './ng_control'; -import {Form} from './form_interface'; -import {NgControlGroup} from './ng_control_group'; +import {AbstractControl, Control, ControlGroup} from '../model'; +import {NG_ASYNC_VALIDATORS, NG_VALIDATORS} from '../validators'; + import {ControlContainer} from './control_container'; -import {AbstractControl, ControlGroup, Control} from '../model'; -import {setUpControl, setUpControlGroup, composeValidators, composeAsyncValidators} from './shared'; -import {NG_VALIDATORS, NG_ASYNC_VALIDATORS} from '../validators'; +import {Form} from './form_interface'; +import {NgControl} from './ng_control'; +import {NgControlGroup} from './ng_control_group'; +import {composeAsyncValidators, composeValidators, setUpControl, setUpControlGroup} from './shared'; export const formDirectiveProvider: any = /*@ts2dart_const*/ {provide: ControlContainer, useExisting: forwardRef(() => NgForm)}; @@ -93,11 +91,12 @@ export class NgForm extends ControlContainer implements Form { form: ControlGroup; ngSubmit = new EventEmitter(); - constructor(@Optional() @Self() @Inject(NG_VALIDATORS) validators: any[], - @Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) asyncValidators: any[]) { + constructor( + @Optional() @Self() @Inject(NG_VALIDATORS) validators: any[], + @Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) asyncValidators: any[]) { super(); - this.form = new ControlGroup({}, null, composeValidators(validators), - composeAsyncValidators(asyncValidators)); + this.form = new ControlGroup( + {}, null, composeValidators(validators), composeAsyncValidators(asyncValidators)); } get submitted(): boolean { return this._submitted; } diff --git a/modules/@angular/common/src/forms-deprecated/directives/ng_form_control.ts b/modules/@angular/common/src/forms-deprecated/directives/ng_form_control.ts index 17b9885079..4c2bf28ddd 100644 --- a/modules/@angular/common/src/forms-deprecated/directives/ng_form_control.ts +++ b/modules/@angular/common/src/forms-deprecated/directives/ng_form_control.ts @@ -1,28 +1,14 @@ -import { - OnChanges, - SimpleChanges, - Directive, - forwardRef, - Inject, - Optional, - Self -} from '@angular/core'; +import {Directive, Inject, OnChanges, Optional, Self, SimpleChanges, forwardRef} from '@angular/core'; -import {StringMapWrapper} from '../../facade/collection'; import {EventEmitter, ObservableWrapper} from '../../facade/async'; - -import {NgControl} from './ng_control'; +import {StringMapWrapper} from '../../facade/collection'; import {Control} from '../model'; -import {NG_VALIDATORS, NG_ASYNC_VALIDATORS} from '../validators'; +import {NG_ASYNC_VALIDATORS, NG_VALIDATORS} from '../validators'; + import {ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor'; -import { - setUpControl, - composeValidators, - composeAsyncValidators, - isPropertyUpdated, - selectValueAccessor -} from './shared'; -import {ValidatorFn, AsyncValidatorFn} from './validators'; +import {NgControl} from './ng_control'; +import {composeAsyncValidators, composeValidators, isPropertyUpdated, selectValueAccessor, setUpControl} from './shared'; +import {AsyncValidatorFn, ValidatorFn} from './validators'; export const formControlBinding: any = /*@ts2dart_const*/ /* @ts2dart_Provider */ { @@ -98,35 +84,37 @@ export class NgFormControl extends NgControl implements OnChanges { /* Array */ any[], @Optional() @Self() @Inject(NG_VALUE_ACCESSOR) valueAccessors: ControlValueAccessor[]) { - super(); - this.valueAccessor = selectValueAccessor(this, valueAccessors); - } + super(); + this.valueAccessor = selectValueAccessor(this, valueAccessors); + } - ngOnChanges(changes: SimpleChanges): void { - if (this._isControlChanged(changes)) { - setUpControl(this.form, this); - this.form.updateValueAndValidity({emitEvent: false}); - } - if (isPropertyUpdated(changes, this.viewModel)) { - this.form.updateValue(this.model); - this.viewModel = this.model; - } - } + ngOnChanges(changes: SimpleChanges): void { + if (this._isControlChanged(changes)) { + setUpControl(this.form, this); + this.form.updateValueAndValidity({emitEvent: false}); + } + if (isPropertyUpdated(changes, this.viewModel)) { + this.form.updateValue(this.model); + this.viewModel = this.model; + } + } - get path(): string[] { return []; } + get path(): string[] { return []; } - get validator(): ValidatorFn { return composeValidators(this._validators); } + get validator(): ValidatorFn { return composeValidators(this._validators); } - get asyncValidator(): AsyncValidatorFn { return composeAsyncValidators(this._asyncValidators); } + get asyncValidator(): AsyncValidatorFn { + return composeAsyncValidators(this._asyncValidators); + } - get control(): Control { return this.form; } + get control(): Control { return this.form; } - viewToModelUpdate(newValue: any): void { - this.viewModel = newValue; - ObservableWrapper.callEmit(this.update, newValue); - } + viewToModelUpdate(newValue: any): void { + this.viewModel = newValue; + ObservableWrapper.callEmit(this.update, newValue); + } - private _isControlChanged(changes: {[key: string]: any}): boolean { - return StringMapWrapper.contains(changes, "form"); - } + private _isControlChanged(changes: {[key: string]: any}): boolean { + return StringMapWrapper.contains(changes, 'form'); + } } diff --git a/modules/@angular/common/src/forms-deprecated/directives/ng_form_model.ts b/modules/@angular/common/src/forms-deprecated/directives/ng_form_model.ts index 9b68180830..30b0669280 100644 --- a/modules/@angular/common/src/forms-deprecated/directives/ng_form_model.ts +++ b/modules/@angular/common/src/forms-deprecated/directives/ng_form_model.ts @@ -1,23 +1,17 @@ -import { - SimpleChanges, - OnChanges, - Directive, - forwardRef, - Inject, - Optional, - Self -} from '@angular/core'; -import {isBlank} from '../../facade/lang'; +import {Directive, Inject, OnChanges, Optional, Self, SimpleChanges, forwardRef} from '@angular/core'; + +import {EventEmitter, ObservableWrapper} from '../../facade/async'; import {ListWrapper, StringMapWrapper} from '../../facade/collection'; import {BaseException} from '../../facade/exceptions'; -import {ObservableWrapper, EventEmitter} from '../../facade/async'; -import {NgControl} from './ng_control'; -import {NgControlGroup} from './ng_control_group'; +import {isBlank} from '../../facade/lang'; +import {Control, ControlGroup} from '../model'; +import {NG_ASYNC_VALIDATORS, NG_VALIDATORS, Validators} from '../validators'; + import {ControlContainer} from './control_container'; import {Form} from './form_interface'; -import {Control, ControlGroup} from '../model'; -import {setUpControl, setUpControlGroup, composeValidators, composeAsyncValidators} from './shared'; -import {Validators, NG_VALIDATORS, NG_ASYNC_VALIDATORS} from '../validators'; +import {NgControl} from './ng_control'; +import {NgControlGroup} from './ng_control_group'; +import {composeAsyncValidators, composeValidators, setUpControl, setUpControlGroup} from './shared'; export const formDirectiveProvider: any = /*@ts2dart_const*/ /* @ts2dart_Provider */ { @@ -115,14 +109,15 @@ export class NgFormModel extends ControlContainer implements Form, directives: NgControl[] = []; ngSubmit = new EventEmitter(); - constructor(@Optional() @Self() @Inject(NG_VALIDATORS) private _validators: any[], - @Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: any[]) { + constructor( + @Optional() @Self() @Inject(NG_VALIDATORS) private _validators: any[], + @Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: any[]) { super(); } ngOnChanges(changes: SimpleChanges): void { this._checkFormPresent(); - if (StringMapWrapper.contains(changes, "form")) { + if (StringMapWrapper.contains(changes, 'form')) { var sync = composeValidators(this._validators); this.form.validator = Validators.compose([this.form.validator, sync]); diff --git a/modules/@angular/common/src/forms-deprecated/directives/ng_model.ts b/modules/@angular/common/src/forms-deprecated/directives/ng_model.ts index ae84f28871..a5205903e4 100644 --- a/modules/@angular/common/src/forms-deprecated/directives/ng_model.ts +++ b/modules/@angular/common/src/forms-deprecated/directives/ng_model.ts @@ -1,25 +1,13 @@ -import { - OnChanges, - SimpleChanges, - Directive, - forwardRef, - Inject, - Optional, - Self -} from '@angular/core'; +import {Directive, Inject, OnChanges, Optional, Self, SimpleChanges, forwardRef} from '@angular/core'; + import {EventEmitter, ObservableWrapper} from '../../facade/async'; +import {Control} from '../model'; +import {NG_ASYNC_VALIDATORS, NG_VALIDATORS} from '../validators'; + import {ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor'; import {NgControl} from './ng_control'; -import {Control} from '../model'; -import {NG_VALIDATORS, NG_ASYNC_VALIDATORS} from '../validators'; -import { - setUpControl, - isPropertyUpdated, - selectValueAccessor, - composeValidators, - composeAsyncValidators -} from './shared'; -import {ValidatorFn, AsyncValidatorFn} from './validators'; +import {composeAsyncValidators, composeValidators, isPropertyUpdated, selectValueAccessor, setUpControl} from './shared'; +import {AsyncValidatorFn, ValidatorFn} from './validators'; export const formControlBinding: any = /*@ts2dart_const*/ /* @ts2dart_Provider */ { @@ -70,33 +58,35 @@ export class NgModel extends NgControl implements OnChanges { @Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: any[], @Optional() @Self() @Inject(NG_VALUE_ACCESSOR) valueAccessors: ControlValueAccessor[]) { - super(); - this.valueAccessor = selectValueAccessor(this, valueAccessors); - } + super(); + this.valueAccessor = selectValueAccessor(this, valueAccessors); + } - ngOnChanges(changes: SimpleChanges) { - if (!this._added) { - setUpControl(this._control, this); - this._control.updateValueAndValidity({emitEvent: false}); - this._added = true; - } + ngOnChanges(changes: SimpleChanges) { + if (!this._added) { + setUpControl(this._control, this); + this._control.updateValueAndValidity({emitEvent: false}); + this._added = true; + } - if (isPropertyUpdated(changes, this.viewModel)) { - this._control.updateValue(this.model); - this.viewModel = this.model; - } - } + if (isPropertyUpdated(changes, this.viewModel)) { + this._control.updateValue(this.model); + this.viewModel = this.model; + } + } - get control(): Control { return this._control; } + get control(): Control { return this._control; } - get path(): string[] { return []; } + get path(): string[] { return []; } - get validator(): ValidatorFn { return composeValidators(this._validators); } + get validator(): ValidatorFn { return composeValidators(this._validators); } - get asyncValidator(): AsyncValidatorFn { return composeAsyncValidators(this._asyncValidators); } + get asyncValidator(): AsyncValidatorFn { + return composeAsyncValidators(this._asyncValidators); + } - viewToModelUpdate(newValue: any): void { - this.viewModel = newValue; - ObservableWrapper.callEmit(this.update, newValue); - } + viewToModelUpdate(newValue: any): void { + this.viewModel = newValue; + ObservableWrapper.callEmit(this.update, newValue); + } } diff --git a/modules/@angular/common/src/forms-deprecated/directives/normalize_validator.ts b/modules/@angular/common/src/forms-deprecated/directives/normalize_validator.ts index c956c8d4ae..d669b78961 100644 --- a/modules/@angular/common/src/forms-deprecated/directives/normalize_validator.ts +++ b/modules/@angular/common/src/forms-deprecated/directives/normalize_validator.ts @@ -1,5 +1,6 @@ import {AbstractControl} from '../model'; -import {Validator, ValidatorFn, AsyncValidatorFn} from './validators'; + +import {AsyncValidatorFn, Validator, ValidatorFn} from './validators'; export function normalizeValidator(validator: ValidatorFn | Validator): ValidatorFn { if ((validator).validate !== undefined) { diff --git a/modules/@angular/common/src/forms-deprecated/directives/number_value_accessor.ts b/modules/@angular/common/src/forms-deprecated/directives/number_value_accessor.ts index ca84ed50af..d5a9763dfa 100644 --- a/modules/@angular/common/src/forms-deprecated/directives/number_value_accessor.ts +++ b/modules/@angular/common/src/forms-deprecated/directives/number_value_accessor.ts @@ -1,6 +1,8 @@ import {Directive, ElementRef, Renderer, forwardRef} from '@angular/core'; + import {NumberWrapper} from '../../facade/lang'; -import {NG_VALUE_ACCESSOR, ControlValueAccessor} from './control_value_accessor'; + +import {ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor'; export const NUMBER_VALUE_ACCESSOR: any = /*@ts2dart_const*/ /*@ts2dart_Provider*/ { provide: NG_VALUE_ACCESSOR, diff --git a/modules/@angular/common/src/forms-deprecated/directives/radio_control_value_accessor.ts b/modules/@angular/common/src/forms-deprecated/directives/radio_control_value_accessor.ts index f87656f195..c74b0433ae 100644 --- a/modules/@angular/common/src/forms-deprecated/directives/radio_control_value_accessor.ts +++ b/modules/@angular/common/src/forms-deprecated/directives/radio_control_value_accessor.ts @@ -1,17 +1,9 @@ -import { - Directive, - ElementRef, - Renderer, - forwardRef, - Input, - OnInit, - OnDestroy, - Injector, - Injectable -} from '@angular/core'; -import {isPresent} from '../../facade/lang'; +import {Directive, ElementRef, Injectable, Injector, Input, OnDestroy, OnInit, Renderer, forwardRef} from '@angular/core'; + import {ListWrapper} from '../../facade/collection'; -import {NG_VALUE_ACCESSOR, ControlValueAccessor} from './control_value_accessor'; +import {isPresent} from '../../facade/lang'; + +import {ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor'; import {NgControl} from './ng_control'; export const RADIO_VALUE_ACCESSOR: any = /*@ts2dart_const*/ /*@ts2dart_Provider*/ { @@ -49,10 +41,10 @@ export class RadioControlRegistry { }); } - private _isSameGroup(controlPair:[NgControl, RadioControlValueAccessor], - accessor: RadioControlValueAccessor) { + private _isSameGroup( + controlPair: [NgControl, RadioControlValueAccessor], accessor: RadioControlValueAccessor) { return controlPair[0].control.root === accessor._control.control.root && - controlPair[1].name === accessor.name; + controlPair[1].name === accessor.name; } } @@ -102,8 +94,9 @@ export class RadioControlValueAccessor implements ControlValueAccessor, onChange = () => {}; onTouched = () => {}; - constructor(private _renderer: Renderer, private _elementRef: ElementRef, - private _registry: RadioControlRegistry, private _injector: Injector) {} + constructor( + private _renderer: Renderer, private _elementRef: ElementRef, + private _registry: RadioControlRegistry, private _injector: Injector) {} ngOnInit(): void { this._control = this._injector.get(NgControl); diff --git a/modules/@angular/common/src/forms-deprecated/directives/select_control_value_accessor.ts b/modules/@angular/common/src/forms-deprecated/directives/select_control_value_accessor.ts index 4ba6d0061b..265f8994da 100644 --- a/modules/@angular/common/src/forms-deprecated/directives/select_control_value_accessor.ts +++ b/modules/@angular/common/src/forms-deprecated/directives/select_control_value_accessor.ts @@ -1,23 +1,9 @@ -import { - Directive, - Renderer, - forwardRef, - ElementRef, - Input, - Host, - OnDestroy, - Optional -} from '@angular/core'; -import { - StringWrapper, - isPrimitive, - isPresent, - isBlank, - looseIdentical -} from '../../facade/lang'; -import {MapWrapper} from '../../facade/collection'; +import {Directive, ElementRef, Host, Input, OnDestroy, Optional, Renderer, forwardRef} from '@angular/core'; -import {NG_VALUE_ACCESSOR, ControlValueAccessor} from './control_value_accessor'; +import {MapWrapper} from '../../facade/collection'; +import {StringWrapper, isBlank, isPresent, isPrimitive, looseIdentical} from '../../facade/lang'; + +import {ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor'; export const SELECT_VALUE_ACCESSOR: any = /*@ts2dart_const*/ /*@ts2dart_Provider*/ { provide: NG_VALUE_ACCESSOR, @@ -27,12 +13,12 @@ export const SELECT_VALUE_ACCESSOR: any = /*@ts2dart_const*/ /*@ts2dart_Provider function _buildValueString(id: string, value: any): string { if (isBlank(id)) return `${value}`; - if (!isPrimitive(value)) value = "Object"; + if (!isPrimitive(value)) value = 'Object'; return StringWrapper.slice(`${id}: ${value}`, 0, 50); } function _extractId(valueString: string): string { - return valueString.split(":")[0]; + return valueString.split(':')[0]; } /** @@ -112,8 +98,9 @@ export class SelectControlValueAccessor implements ControlValueAccessor { export class NgSelectOption implements OnDestroy { id: string; - constructor(private _element: ElementRef, private _renderer: Renderer, - @Optional() @Host() private _select: SelectControlValueAccessor) { + constructor( + private _element: ElementRef, private _renderer: Renderer, + @Optional() @Host() private _select: SelectControlValueAccessor) { if (isPresent(this._select)) this.id = this._select._registerOption(); } diff --git a/modules/@angular/common/src/forms-deprecated/directives/select_multiple_control_value_accessor.ts b/modules/@angular/common/src/forms-deprecated/directives/select_multiple_control_value_accessor.ts index f2f981ebb3..4e39059d9f 100644 --- a/modules/@angular/common/src/forms-deprecated/directives/select_multiple_control_value_accessor.ts +++ b/modules/@angular/common/src/forms-deprecated/directives/select_multiple_control_value_accessor.ts @@ -1,23 +1,9 @@ -import { - Input, - Directive, - ElementRef, - Renderer, - Optional, - Host, - OnDestroy, - forwardRef -} from "@angular/core"; -import { - isBlank, - isPrimitive, - StringWrapper, - isPresent, - looseIdentical, - isString -} from '../../facade/lang'; -import {ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor'; +import {Directive, ElementRef, Host, Input, OnDestroy, Optional, Renderer, forwardRef} from '@angular/core'; + import {MapWrapper} from '../../facade/collection'; +import {StringWrapper, isBlank, isPresent, isPrimitive, isString, looseIdentical} from '../../facade/lang'; + +import {ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor'; const SELECT_MULTIPLE_VALUE_ACCESSOR = { provide: NG_VALUE_ACCESSOR, @@ -28,12 +14,12 @@ const SELECT_MULTIPLE_VALUE_ACCESSOR = { function _buildValueString(id: string, value: any): string { if (isBlank(id)) return `${value}`; if (isString(value)) value = `'${value}'`; - if (!isPrimitive(value)) value = "Object"; + if (!isPrimitive(value)) value = 'Object'; return StringWrapper.slice(`${id}: ${value}`, 0, 50); } function _extractId(valueString: string): string { - return valueString.split(":")[0]; + return valueString.split(':')[0]; } /** Mock interface for HTML Options */ @@ -74,9 +60,7 @@ export class SelectMultipleControlValueAccessor implements ControlValueAccessor let values: Array = >value; // convert values to ids let ids = values.map((v) => this._getOptionId(v)); - this._optionMap.forEach((opt, o) => { - opt._setSelected(ids.indexOf(o.toString()) > -1); - }); + this._optionMap.forEach((opt, o) => { opt._setSelected(ids.indexOf(o.toString()) > -1); }); } registerOnChange(fn: (value: any) => any): void { @@ -108,7 +92,7 @@ export class SelectMultipleControlValueAccessor implements ControlValueAccessor /** @internal */ _registerOption(value: NgSelectMultipleOption): string { - let id:string = (this._idCounter++).toString(); + let id: string = (this._idCounter++).toString(); this._optionMap.set(id, value); return id; } @@ -145,8 +129,9 @@ export class NgSelectMultipleOption implements OnDestroy { /** @internal */ _value: any; - constructor(private _element: ElementRef, private _renderer: Renderer, - @Optional() @Host() private _select: SelectMultipleControlValueAccessor) { + constructor( + private _element: ElementRef, private _renderer: Renderer, + @Optional() @Host() private _select: SelectMultipleControlValueAccessor) { if (isPresent(this._select)) { this.id = this._select._registerOption(this); } diff --git a/modules/@angular/common/src/forms-deprecated/directives/shared.ts b/modules/@angular/common/src/forms-deprecated/directives/shared.ts index 8baceaf856..8d300e82e8 100644 --- a/modules/@angular/common/src/forms-deprecated/directives/shared.ts +++ b/modules/@angular/common/src/forms-deprecated/directives/shared.ts @@ -1,21 +1,21 @@ import {ListWrapper, StringMapWrapper} from '../../facade/collection'; -import {isBlank, isPresent, looseIdentical, hasConstructor} from '../../facade/lang'; import {BaseException} from '../../facade/exceptions'; - -import {ControlContainer} from './control_container'; -import {NgControl} from './ng_control'; -import {AbstractControlDirective} from './abstract_control_directive'; -import {NgControlGroup} from './ng_control_group'; +import {hasConstructor, isBlank, isPresent, looseIdentical} from '../../facade/lang'; import {Control, ControlGroup} from '../model'; import {Validators} from '../validators'; + +import {AbstractControlDirective} from './abstract_control_directive'; +import {CheckboxControlValueAccessor} from './checkbox_value_accessor'; +import {ControlContainer} from './control_container'; import {ControlValueAccessor} from './control_value_accessor'; import {DefaultValueAccessor} from './default_value_accessor'; +import {NgControl} from './ng_control'; +import {NgControlGroup} from './ng_control_group'; +import {normalizeAsyncValidator, normalizeValidator} from './normalize_validator'; import {NumberValueAccessor} from './number_value_accessor'; -import {CheckboxControlValueAccessor} from './checkbox_value_accessor'; -import {SelectControlValueAccessor} from './select_control_value_accessor'; import {RadioControlValueAccessor} from './radio_control_value_accessor'; -import {normalizeValidator, normalizeAsyncValidator} from './normalize_validator'; -import {ValidatorFn, AsyncValidatorFn} from './validators'; +import {SelectControlValueAccessor} from './select_control_value_accessor'; +import {AsyncValidatorFn, ValidatorFn} from './validators'; export function controlPath(name: string, parent: ControlContainer): string[] { @@ -25,8 +25,8 @@ export function controlPath(name: string, parent: ControlContainer): string[] { } export function setUpControl(control: Control, dir: NgControl): void { - if (isBlank(control)) _throwError(dir, "Cannot find control"); - if (isBlank(dir.valueAccessor)) _throwError(dir, "No value accessor for"); + if (isBlank(control)) _throwError(dir, 'Cannot find control'); + if (isBlank(dir.valueAccessor)) _throwError(dir, 'No value accessor for'); control.validator = Validators.compose([control.validator, dir.validator]); control.asyncValidator = Validators.composeAsync([control.asyncValidator, dir.asyncValidator]); @@ -47,13 +47,13 @@ export function setUpControl(control: Control, dir: NgControl): void { } export function setUpControlGroup(control: ControlGroup, dir: NgControlGroup) { - if (isBlank(control)) _throwError(dir, "Cannot find control"); + if (isBlank(control)) _throwError(dir, 'Cannot find control'); control.validator = Validators.compose([control.validator, dir.validator]); control.asyncValidator = Validators.composeAsync([control.asyncValidator, dir.asyncValidator]); } function _throwError(dir: AbstractControlDirective, message: string): void { - var path = dir.path.join(" -> "); + var path = dir.path.join(' -> '); throw new BaseException(`${message} '${path}'`); } @@ -61,23 +61,23 @@ export function composeValidators(validators: /* Array */ an return isPresent(validators) ? Validators.compose(validators.map(normalizeValidator)) : null; } -export function composeAsyncValidators( - validators: /* Array */ any[]): AsyncValidatorFn { +export function composeAsyncValidators(validators: /* Array */ any[]): + AsyncValidatorFn { return isPresent(validators) ? Validators.composeAsync(validators.map(normalizeAsyncValidator)) : null; } export function isPropertyUpdated(changes: {[key: string]: any}, viewModel: any): boolean { - if (!StringMapWrapper.contains(changes, "model")) return false; - var change = changes["model"]; + if (!StringMapWrapper.contains(changes, 'model')) return false; + var change = changes['model']; if (change.isFirstChange()) return true; return !looseIdentical(viewModel, change.currentValue); } // TODO: vsavkin remove it once https://github.com/angular/angular/issues/3011 is implemented -export function selectValueAccessor(dir: NgControl, - valueAccessors: ControlValueAccessor[]): ControlValueAccessor { +export function selectValueAccessor( + dir: NgControl, valueAccessors: ControlValueAccessor[]): ControlValueAccessor { if (isBlank(valueAccessors)) return null; var defaultAccessor: ControlValueAccessor; @@ -87,17 +87,17 @@ export function selectValueAccessor(dir: NgControl, if (hasConstructor(v, DefaultValueAccessor)) { defaultAccessor = v; - } else if (hasConstructor(v, CheckboxControlValueAccessor) || - hasConstructor(v, NumberValueAccessor) || - hasConstructor(v, SelectControlValueAccessor) || - hasConstructor(v, RadioControlValueAccessor)) { + } else if ( + hasConstructor(v, CheckboxControlValueAccessor) || hasConstructor(v, NumberValueAccessor) || + hasConstructor(v, SelectControlValueAccessor) || + hasConstructor(v, RadioControlValueAccessor)) { if (isPresent(builtinAccessor)) - _throwError(dir, "More than one built-in value accessor matches"); + _throwError(dir, 'More than one built-in value accessor matches'); builtinAccessor = v; } else { if (isPresent(customAccessor)) - _throwError(dir, "More than one custom value accessor matches"); + _throwError(dir, 'More than one custom value accessor matches'); customAccessor = v; } }); @@ -106,6 +106,6 @@ export function selectValueAccessor(dir: NgControl, if (isPresent(builtinAccessor)) return builtinAccessor; if (isPresent(defaultAccessor)) return defaultAccessor; - _throwError(dir, "No valid value accessor for"); + _throwError(dir, 'No valid value accessor for'); return null; } diff --git a/modules/@angular/common/src/forms-deprecated/directives/validators.ts b/modules/@angular/common/src/forms-deprecated/directives/validators.ts index 0e60918edd..401941f8f8 100644 --- a/modules/@angular/common/src/forms-deprecated/directives/validators.ts +++ b/modules/@angular/common/src/forms-deprecated/directives/validators.ts @@ -1,7 +1,8 @@ -import {forwardRef, Attribute, Directive} from '@angular/core'; +import {Attribute, Directive, forwardRef} from '@angular/core'; + import {NumberWrapper} from '../../facade/lang'; -import {Validators, NG_VALIDATORS} from '../validators'; import {AbstractControl} from '../model'; +import {NG_VALIDATORS, Validators} from '../validators'; @@ -82,7 +83,7 @@ export const MIN_LENGTH_VALIDATOR: any = /*@ts2dart_const*/ /*@ts2dart_Provider* export class MinLengthValidator implements Validator { private _validator: ValidatorFn; - constructor(@Attribute("minlength") minLength: string) { + constructor(@Attribute('minlength') minLength: string) { this._validator = Validators.minLength(NumberWrapper.parseInt(minLength, 10)); } @@ -115,7 +116,7 @@ export const MAX_LENGTH_VALIDATOR: any = /*@ts2dart_const*/ /*@ts2dart_Provider* export class MaxLengthValidator implements Validator { private _validator: ValidatorFn; - constructor(@Attribute("maxlength") maxLength: string) { + constructor(@Attribute('maxlength') maxLength: string) { this._validator = Validators.maxLength(NumberWrapper.parseInt(maxLength, 10)); } @@ -150,7 +151,7 @@ export const PATTERN_VALIDATOR: any = /*@ts2dart_const*/ /*@ts2dart_Provider*/ { export class PatternValidator implements Validator { private _validator: ValidatorFn; - constructor(@Attribute("pattern") pattern: string) { + constructor(@Attribute('pattern') pattern: string) { this._validator = Validators.pattern(pattern); } diff --git a/modules/@angular/common/src/forms-deprecated/form_builder.ts b/modules/@angular/common/src/forms-deprecated/form_builder.ts index b388606c76..5289d1cd09 100644 --- a/modules/@angular/common/src/forms-deprecated/form_builder.ts +++ b/modules/@angular/common/src/forms-deprecated/form_builder.ts @@ -1,8 +1,11 @@ import {Injectable} from '@angular/core'; + import {StringMapWrapper} from '../facade/collection'; -import {isPresent, isArray} from '../facade/lang'; +import {isArray, isPresent} from '../facade/lang'; + +import {AsyncValidatorFn, ValidatorFn} from './directives/validators'; import * as modelModule from './model'; -import {ValidatorFn, AsyncValidatorFn} from './directives/validators'; + /** @@ -56,21 +59,21 @@ export class FormBuilder { * * See the {@link ControlGroup} constructor for more details. */ - group(controlsConfig: {[key: string]: any}, - extra: {[key: string]: any} = null): modelModule.ControlGroup { + group(controlsConfig: {[key: string]: any}, extra: {[key: string]: any} = null): + modelModule.ControlGroup { var controls = this._reduceControls(controlsConfig); var optionals = <{[key: string]: boolean}>( - isPresent(extra) ? StringMapWrapper.get(extra, "optionals") : null); - var validator: ValidatorFn = isPresent(extra) ? StringMapWrapper.get(extra, "validator") : null; + isPresent(extra) ? StringMapWrapper.get(extra, 'optionals') : null); + var validator: ValidatorFn = isPresent(extra) ? StringMapWrapper.get(extra, 'validator') : null; var asyncValidator: AsyncValidatorFn = - isPresent(extra) ? StringMapWrapper.get(extra, "asyncValidator") : null; + isPresent(extra) ? StringMapWrapper.get(extra, 'asyncValidator') : null; return new modelModule.ControlGroup(controls, optionals, validator, asyncValidator); } /** * Construct a new {@link Control} with the given `value`,`validator`, and `asyncValidator`. */ - control(value: Object, validator: ValidatorFn = null, - asyncValidator: AsyncValidatorFn = null): modelModule.Control { + control(value: Object, validator: ValidatorFn = null, asyncValidator: AsyncValidatorFn = null): + modelModule.Control { return new modelModule.Control(value, validator, asyncValidator); } @@ -78,15 +81,16 @@ export class FormBuilder { * Construct an array of {@link Control}s from the given `controlsConfig` array of * configuration, with the given optional `validator` and `asyncValidator`. */ - array(controlsConfig: any[], validator: ValidatorFn = null, - asyncValidator: AsyncValidatorFn = null): modelModule.ControlArray { + array( + controlsConfig: any[], validator: ValidatorFn = null, + asyncValidator: AsyncValidatorFn = null): modelModule.ControlArray { var controls = controlsConfig.map(c => this._createControl(c)); return new modelModule.ControlArray(controls, validator, asyncValidator); } /** @internal */ - _reduceControls(controlsConfig: {[k: string]: - any}): {[key: string]: modelModule.AbstractControl} { + _reduceControls(controlsConfig: {[k: string]: any}): + {[key: string]: modelModule.AbstractControl} { var controls: {[key: string]: modelModule.AbstractControl} = {}; StringMapWrapper.forEach(controlsConfig, (controlConfig: any, controlName: string) => { controls[controlName] = this._createControl(controlConfig); diff --git a/modules/@angular/common/src/forms-deprecated/model.ts b/modules/@angular/common/src/forms-deprecated/model.ts index 3741d2e079..b0151e09db 100644 --- a/modules/@angular/common/src/forms-deprecated/model.ts +++ b/modules/@angular/common/src/forms-deprecated/model.ts @@ -1,48 +1,49 @@ -import {isPresent, isBlank, normalizeBool} from '../facade/lang'; -import {Observable, EventEmitter, ObservableWrapper} from '../facade/async'; +import {EventEmitter, Observable, ObservableWrapper} from '../facade/async'; +import {ListWrapper, StringMapWrapper} from '../facade/collection'; +import {isBlank, isPresent, normalizeBool} from '../facade/lang'; import {PromiseWrapper} from '../facade/promise'; -import {StringMapWrapper, ListWrapper} from '../facade/collection'; -import {ValidatorFn, AsyncValidatorFn} from './directives/validators'; + +import {AsyncValidatorFn, ValidatorFn} from './directives/validators'; + /** * Indicates that a Control is valid, i.e. that no errors exist in the input value. */ -export const VALID = "VALID"; +export const VALID = 'VALID'; /** * Indicates that a Control is invalid, i.e. that an error exists in the input value. */ -export const INVALID = "INVALID"; +export const INVALID = 'INVALID'; /** * Indicates that a Control is pending, i.e. that async validation is occurring and * errors are not yet available for the input value. */ -export const PENDING = "PENDING"; +export const PENDING = 'PENDING'; export function isControl(control: Object): boolean { return control instanceof AbstractControl; } -function _find(control: AbstractControl, path: Array| string) { +function _find(control: AbstractControl, path: Array| string) { if (isBlank(path)) return null; if (!(path instanceof Array)) { - path = (path).split("/"); + path = (path).split('/'); } if (path instanceof Array && ListWrapper.isEmpty(path)) return null; - return (>path) - .reduce((v, name) => { - if (v instanceof ControlGroup) { - return isPresent(v.controls[name]) ? v.controls[name] : null; - } else if (v instanceof ControlArray) { - var index = name; - return isPresent(v.at(index)) ? v.at(index) : null; - } else { - return null; - } - }, control); + return (>path).reduce((v, name) => { + if (v instanceof ControlGroup) { + return isPresent(v.controls[name]) ? v.controls[name] : null; + } else if (v instanceof ControlArray) { + var index = name; + return isPresent(v.at(index)) ? v.at(index) : null; + } else { + return null; + } + }, control); } function toObservable(r: any): Observable { @@ -62,7 +63,7 @@ export abstract class AbstractControl { private _errors: {[key: string]: any}; private _pristine: boolean = true; private _touched: boolean = false; - private _parent: ControlGroup | ControlArray; + private _parent: ControlGroup|ControlArray; private _asyncValidationSubscription: any; constructor(public validator: ValidatorFn, public asyncValidator: AsyncValidatorFn) {} @@ -112,10 +113,10 @@ export abstract class AbstractControl { } } - setParent(parent: ControlGroup | ControlArray): void { this._parent = parent; } + setParent(parent: ControlGroup|ControlArray): void { this._parent = parent; } - updateValueAndValidity( - {onlySelf, emitEvent}: {onlySelf?: boolean, emitEvent?: boolean} = {}): void { + updateValueAndValidity({onlySelf, emitEvent}: {onlySelf?: boolean, emitEvent?: boolean} = {}): + void { onlySelf = normalizeBool(onlySelf); emitEvent = isPresent(emitEvent) ? emitEvent : true; @@ -196,7 +197,7 @@ export abstract class AbstractControl { } } - find(path: Array| string): AbstractControl { return _find(this, path); } + find(path: Array|string): AbstractControl { return _find(this, path); } getError(errorCode: string, path: string[] = null): any { var control = isPresent(path) && !ListWrapper.isEmpty(path) ? this.find(path) : this; @@ -273,8 +274,8 @@ export class Control extends AbstractControl { /** @internal */ _onChange: Function; - constructor(value: any = null, validator: ValidatorFn = null, - asyncValidator: AsyncValidatorFn = null) { + constructor( + value: any = null, validator: ValidatorFn = null, asyncValidator: AsyncValidatorFn = null) { super(validator, asyncValidator); this._value = value; this.updateValueAndValidity({onlySelf: true, emitEvent: false}); @@ -339,9 +340,9 @@ export class Control extends AbstractControl { export class ControlGroup extends AbstractControl { private _optionals: {[key: string]: boolean}; - constructor(public controls: {[key: string]: AbstractControl}, - optionals: {[key: string]: boolean} = null, validator: ValidatorFn = null, - asyncValidator: AsyncValidatorFn = null) { + constructor( + public controls: {[key: string]: AbstractControl}, optionals: {[key: string]: boolean} = null, + validator: ValidatorFn = null, asyncValidator: AsyncValidatorFn = null) { super(validator, asyncValidator); this._optionals = isPresent(optionals) ? optionals : {}; this._initObservables(); @@ -467,8 +468,9 @@ export class ControlGroup extends AbstractControl { * @experimental */ export class ControlArray extends AbstractControl { - constructor(public controls: AbstractControl[], validator: ValidatorFn = null, - asyncValidator: AsyncValidatorFn = null) { + constructor( + public controls: AbstractControl[], validator: ValidatorFn = null, + asyncValidator: AsyncValidatorFn = null) { super(validator, asyncValidator); this._initObservables(); this._setParentForControls(); diff --git a/modules/@angular/common/src/forms-deprecated/validators.ts b/modules/@angular/common/src/forms-deprecated/validators.ts index 0be2d8a321..b1958da086 100644 --- a/modules/@angular/common/src/forms-deprecated/validators.ts +++ b/modules/@angular/common/src/forms-deprecated/validators.ts @@ -1,10 +1,13 @@ import {OpaqueToken} from '@angular/core'; -import {isBlank, isPresent, isString} from '../facade/lang'; -import {PromiseWrapper} from '../facade/promise'; + import {ObservableWrapper} from '../facade/async'; import {StringMapWrapper} from '../facade/collection'; +import {isBlank, isPresent, isString} from '../facade/lang'; +import {PromiseWrapper} from '../facade/promise'; + +import {AsyncValidatorFn, ValidatorFn} from './directives/validators'; import * as modelModule from './model'; -import {ValidatorFn, AsyncValidatorFn} from './directives/validators'; + /** * Providers for validators to be used for {@link Control}s in a form. @@ -16,7 +19,7 @@ import {ValidatorFn, AsyncValidatorFn} from './directives/validators'; * {@example core/forms/ts/ng_validators/ng_validators.ts region='ng_validators'} * @experimental */ -export const NG_VALIDATORS: OpaqueToken = /*@ts2dart_const*/ new OpaqueToken("NgValidators"); +export const NG_VALIDATORS: OpaqueToken = /*@ts2dart_const*/ new OpaqueToken('NgValidators'); /** * Providers for asynchronous validators to be used for {@link Control}s @@ -29,7 +32,7 @@ export const NG_VALIDATORS: OpaqueToken = /*@ts2dart_const*/ new OpaqueToken("Ng * @experimental */ export const NG_ASYNC_VALIDATORS: OpaqueToken = - /*@ts2dart_const*/ new OpaqueToken("NgAsyncValidators"); + /*@ts2dart_const*/ new OpaqueToken('NgAsyncValidators'); /** * Provides a set of validators used by form controls. @@ -50,9 +53,9 @@ export class Validators { * Validator that requires controls to have a non-empty value. */ static required(control: modelModule.AbstractControl): {[key: string]: boolean} { - return isBlank(control.value) || (isString(control.value) && control.value == "") ? - {"required": true} : - null; + return isBlank(control.value) || (isString(control.value) && control.value == '') ? + {'required': true} : + null; } /** @@ -63,8 +66,8 @@ export class Validators { if (isPresent(Validators.required(control))) return null; var v: string = control.value; return v.length < minLength ? - {"minlength": {"requiredLength": minLength, "actualLength": v.length}} : - null; + {'minlength': {'requiredLength': minLength, 'actualLength': v.length}} : + null; }; } @@ -76,8 +79,8 @@ export class Validators { if (isPresent(Validators.required(control))) return null; var v: string = control.value; return v.length > maxLength ? - {"maxlength": {"requiredLength": maxLength, "actualLength": v.length}} : - null; + {'maxlength': {'requiredLength': maxLength, 'actualLength': v.length}} : + null; }; } @@ -90,7 +93,7 @@ export class Validators { let regex = new RegExp(`^${pattern}$`); let v: string = control.value; return regex.test(v) ? null : - {"pattern": {"requiredPattern": `^${pattern}$`, "actualValue": v}}; + {'pattern': {'requiredPattern': `^${pattern}$`, 'actualValue': v}}; }; } @@ -129,13 +132,13 @@ function _convertToPromise(obj: any): any { return PromiseWrapper.isPromise(obj) ? obj : ObservableWrapper.toPromise(obj); } -function _executeValidators(control: modelModule.AbstractControl, - validators: ValidatorFn[]): any[] { +function _executeValidators( + control: modelModule.AbstractControl, validators: ValidatorFn[]): any[] { return validators.map(v => v(control)); } -function _executeAsyncValidators(control: modelModule.AbstractControl, - validators: AsyncValidatorFn[]): any[] { +function _executeAsyncValidators( + control: modelModule.AbstractControl, validators: AsyncValidatorFn[]): any[] { return validators.map(v => v(control)); } diff --git a/modules/@angular/common/src/forms.ts b/modules/@angular/common/src/forms.ts index 13c6f31d74..8bae2c2226 100644 --- a/modules/@angular/common/src/forms.ts +++ b/modules/@angular/common/src/forms.ts @@ -10,39 +10,32 @@ * Forms providers are not included in default providers; you must import these providers * explicitly. */ -export {AbstractControl, Control, ControlGroup, ControlArray} from './forms/model'; +import {Type} from '@angular/core'; +import {RadioControlRegistry} from './forms/directives/radio_control_value_accessor'; +import {FormBuilder} from './forms/form_builder'; + +export {FORM_DIRECTIVES, RadioButtonState} from './forms/directives'; export {AbstractControlDirective} from './forms/directives/abstract_control_directive'; -export {Form} from './forms/directives/form_interface'; +export {CheckboxControlValueAccessor} from './forms/directives/checkbox_value_accessor'; export {ControlContainer} from './forms/directives/control_container'; -export {NgControlName} from './forms/directives/ng_control_name'; -export {NgFormControl} from './forms/directives/ng_form_control'; -export {NgModel} from './forms/directives/ng_model'; -export {NgControl} from './forms/directives/ng_control'; -export {NgControlGroup} from './forms/directives/ng_control_group'; -export {NgFormModel} from './forms/directives/ng_form_model'; -export {NgForm} from './forms/directives/ng_form'; export {ControlValueAccessor, NG_VALUE_ACCESSOR} from './forms/directives/control_value_accessor'; export {DefaultValueAccessor} from './forms/directives/default_value_accessor'; +export {Form} from './forms/directives/form_interface'; +export {NgControl} from './forms/directives/ng_control'; +export {NgControlGroup} from './forms/directives/ng_control_group'; +export {NgControlName} from './forms/directives/ng_control_name'; export {NgControlStatus} from './forms/directives/ng_control_status'; -export {CheckboxControlValueAccessor} from './forms/directives/checkbox_value_accessor'; -export { - NgSelectOption, - SelectControlValueAccessor -} from './forms/directives/select_control_value_accessor'; -export {FORM_DIRECTIVES, RadioButtonState} from './forms/directives'; -export {NG_VALIDATORS, NG_ASYNC_VALIDATORS, Validators} from './forms/validators'; -export { - RequiredValidator, - MinLengthValidator, - MaxLengthValidator, - PatternValidator, - Validator -} from './forms/directives/validators'; +export {NgForm} from './forms/directives/ng_form'; +export {NgFormControl} from './forms/directives/ng_form_control'; +export {NgFormModel} from './forms/directives/ng_form_model'; +export {NgModel} from './forms/directives/ng_model'; +export {NgSelectOption, SelectControlValueAccessor} from './forms/directives/select_control_value_accessor'; +export {MaxLengthValidator, MinLengthValidator, PatternValidator, RequiredValidator, Validator} from './forms/directives/validators'; export {FormBuilder} from './forms/form_builder'; -import {FormBuilder} from './forms/form_builder'; -import {RadioControlRegistry} from './forms/directives/radio_control_value_accessor'; -import {Type} from '@angular/core'; +export {AbstractControl, Control, ControlArray, ControlGroup} from './forms/model'; +export {NG_ASYNC_VALIDATORS, NG_VALIDATORS, Validators} from './forms/validators'; + /** * Shorthand set of providers used for building Angular forms. diff --git a/modules/@angular/common/src/forms/directives.ts b/modules/@angular/common/src/forms/directives.ts index 6f370f5796..d2555f8138 100644 --- a/modules/@angular/common/src/forms/directives.ts +++ b/modules/@angular/common/src/forms/directives.ts @@ -1,60 +1,37 @@ import {Type} from '@angular/core'; -import {NgControlName} from './directives/ng_control_name'; -import {NgFormControl} from './directives/ng_form_control'; -import {NgModel} from './directives/ng_model'; -import {NgControlGroup} from './directives/ng_control_group'; -import {NgFormModel} from './directives/ng_form_model'; -import {NgForm} from './directives/ng_form'; -import {DefaultValueAccessor} from './directives/default_value_accessor'; + import {CheckboxControlValueAccessor} from './directives/checkbox_value_accessor'; +import {DefaultValueAccessor} from './directives/default_value_accessor'; +import {NgControlGroup} from './directives/ng_control_group'; +import {NgControlName} from './directives/ng_control_name'; +import {NgControlStatus} from './directives/ng_control_status'; +import {NgForm} from './directives/ng_form'; +import {NgFormControl} from './directives/ng_form_control'; +import {NgFormModel} from './directives/ng_form_model'; +import {NgModel} from './directives/ng_model'; import {NumberValueAccessor} from './directives/number_value_accessor'; import {RadioControlValueAccessor} from './directives/radio_control_value_accessor'; -import {NgControlStatus} from './directives/ng_control_status'; -import { - SelectControlValueAccessor, - NgSelectOption -} from './directives/select_control_value_accessor'; -import { - SelectMultipleControlValueAccessor, - NgSelectMultipleOption -} from './directives/select_multiple_control_value_accessor'; -import { - RequiredValidator, - MinLengthValidator, - MaxLengthValidator, - PatternValidator -} from './directives/validators'; +import {NgSelectOption, SelectControlValueAccessor} from './directives/select_control_value_accessor'; +import {NgSelectMultipleOption, SelectMultipleControlValueAccessor} from './directives/select_multiple_control_value_accessor'; +import {MaxLengthValidator, MinLengthValidator, PatternValidator, RequiredValidator} from './directives/validators'; -export {NgControlName} from './directives/ng_control_name'; -export {NgFormControl} from './directives/ng_form_control'; -export {NgModel} from './directives/ng_model'; -export {NgControlGroup} from './directives/ng_control_group'; -export {NgFormModel} from './directives/ng_form_model'; -export {NgForm} from './directives/ng_form'; -export {DefaultValueAccessor} from './directives/default_value_accessor'; export {CheckboxControlValueAccessor} from './directives/checkbox_value_accessor'; -export { - RadioControlValueAccessor, - RadioButtonState -} from './directives/radio_control_value_accessor'; -export {NumberValueAccessor} from './directives/number_value_accessor'; -export {NgControlStatus} from './directives/ng_control_status'; -export { - SelectControlValueAccessor, - NgSelectOption -} from './directives/select_control_value_accessor'; -export { - SelectMultipleControlValueAccessor, - NgSelectMultipleOption -} from './directives/select_multiple_control_value_accessor'; -export { - RequiredValidator, - MinLengthValidator, - MaxLengthValidator, - PatternValidator -} from './directives/validators'; -export {NgControl} from './directives/ng_control'; export {ControlValueAccessor} from './directives/control_value_accessor'; +export {DefaultValueAccessor} from './directives/default_value_accessor'; +export {NgControl} from './directives/ng_control'; +export {NgControlGroup} from './directives/ng_control_group'; +export {NgControlName} from './directives/ng_control_name'; +export {NgControlStatus} from './directives/ng_control_status'; +export {NgForm} from './directives/ng_form'; +export {NgFormControl} from './directives/ng_form_control'; +export {NgFormModel} from './directives/ng_form_model'; +export {NgModel} from './directives/ng_model'; +export {NumberValueAccessor} from './directives/number_value_accessor'; +export {RadioButtonState, RadioControlValueAccessor} from './directives/radio_control_value_accessor'; +export {NgSelectOption, SelectControlValueAccessor} from './directives/select_control_value_accessor'; +export {NgSelectMultipleOption, SelectMultipleControlValueAccessor} from './directives/select_multiple_control_value_accessor'; +export {MaxLengthValidator, MinLengthValidator, PatternValidator, RequiredValidator} from './directives/validators'; + /** * @@ -74,26 +51,13 @@ export {ControlValueAccessor} from './directives/control_value_accessor'; * @experimental */ export const FORM_DIRECTIVES: Type[] = /*@ts2dart_const*/[ - NgControlName, - NgControlGroup, + NgControlName, NgControlGroup, - NgFormControl, - NgModel, - NgFormModel, - NgForm, + NgFormControl, NgModel, NgFormModel, NgForm, - NgSelectOption, - NgSelectMultipleOption, - DefaultValueAccessor, - NumberValueAccessor, - CheckboxControlValueAccessor, - SelectControlValueAccessor, - SelectMultipleControlValueAccessor, - RadioControlValueAccessor, - NgControlStatus, + NgSelectOption, NgSelectMultipleOption, DefaultValueAccessor, NumberValueAccessor, + CheckboxControlValueAccessor, SelectControlValueAccessor, SelectMultipleControlValueAccessor, + RadioControlValueAccessor, NgControlStatus, - RequiredValidator, - MinLengthValidator, - MaxLengthValidator, - PatternValidator + RequiredValidator, MinLengthValidator, MaxLengthValidator, PatternValidator ]; diff --git a/modules/@angular/common/src/forms/directives/abstract_control_directive.ts b/modules/@angular/common/src/forms/directives/abstract_control_directive.ts index 584d1cb976..19155a3551 100644 --- a/modules/@angular/common/src/forms/directives/abstract_control_directive.ts +++ b/modules/@angular/common/src/forms/directives/abstract_control_directive.ts @@ -1,6 +1,7 @@ -import {AbstractControl} from '../model'; -import {isPresent} from '../../facade/lang'; import {unimplemented} from '../../facade/exceptions'; +import {isPresent} from '../../facade/lang'; +import {AbstractControl} from '../model'; + /** * Base class for control directives. diff --git a/modules/@angular/common/src/forms/directives/checkbox_value_accessor.ts b/modules/@angular/common/src/forms/directives/checkbox_value_accessor.ts index 15a1c9b238..0c37fda55b 100644 --- a/modules/@angular/common/src/forms/directives/checkbox_value_accessor.ts +++ b/modules/@angular/common/src/forms/directives/checkbox_value_accessor.ts @@ -1,5 +1,6 @@ -import {Directive, Renderer, ElementRef, forwardRef} from '@angular/core'; -import {NG_VALUE_ACCESSOR, ControlValueAccessor} from './control_value_accessor'; +import {Directive, ElementRef, Renderer, forwardRef} from '@angular/core'; + +import {ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor'; export const CHECKBOX_VALUE_ACCESSOR: any = /*@ts2dart_const*/ { provide: NG_VALUE_ACCESSOR, diff --git a/modules/@angular/common/src/forms/directives/control_container.ts b/modules/@angular/common/src/forms/directives/control_container.ts index e321b51aa8..23ce459784 100644 --- a/modules/@angular/common/src/forms/directives/control_container.ts +++ b/modules/@angular/common/src/forms/directives/control_container.ts @@ -1,5 +1,6 @@ -import {Form} from './form_interface'; import {AbstractControlDirective} from './abstract_control_directive'; +import {Form} from './form_interface'; + /** * A directive that contains multiple {@link NgControl}s. diff --git a/modules/@angular/common/src/forms/directives/control_value_accessor.ts b/modules/@angular/common/src/forms/directives/control_value_accessor.ts index f080268e77..2ea1adfdc9 100644 --- a/modules/@angular/common/src/forms/directives/control_value_accessor.ts +++ b/modules/@angular/common/src/forms/directives/control_value_accessor.ts @@ -34,4 +34,4 @@ export interface ControlValueAccessor { * @experimental */ export const NG_VALUE_ACCESSOR: OpaqueToken = - /*@ts2dart_const*/ new OpaqueToken("NgValueAccessor"); + /*@ts2dart_const*/ new OpaqueToken('NgValueAccessor'); diff --git a/modules/@angular/common/src/forms/directives/default_value_accessor.ts b/modules/@angular/common/src/forms/directives/default_value_accessor.ts index e8a962cc66..fa7bef3587 100644 --- a/modules/@angular/common/src/forms/directives/default_value_accessor.ts +++ b/modules/@angular/common/src/forms/directives/default_value_accessor.ts @@ -1,6 +1,8 @@ import {Directive, ElementRef, Renderer, forwardRef} from '@angular/core'; + import {isBlank} from '../../facade/lang'; -import {NG_VALUE_ACCESSOR, ControlValueAccessor} from './control_value_accessor'; + +import {ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor'; export const DEFAULT_VALUE_ACCESSOR: any = /*@ts2dart_const*/ /* @ts2dart_Provider */ { diff --git a/modules/@angular/common/src/forms/directives/form_interface.ts b/modules/@angular/common/src/forms/directives/form_interface.ts index f1092f46b2..fe16d01627 100644 --- a/modules/@angular/common/src/forms/directives/form_interface.ts +++ b/modules/@angular/common/src/forms/directives/form_interface.ts @@ -1,6 +1,8 @@ +import {Control, ControlGroup} from '../model'; + import {NgControl} from './ng_control'; import {NgControlGroup} from './ng_control_group'; -import {Control, ControlGroup} from '../model'; + /** * An interface that {@link NgFormModel} and {@link NgForm} implement. diff --git a/modules/@angular/common/src/forms/directives/ng_control.ts b/modules/@angular/common/src/forms/directives/ng_control.ts index f96af30570..e9d237b307 100644 --- a/modules/@angular/common/src/forms/directives/ng_control.ts +++ b/modules/@angular/common/src/forms/directives/ng_control.ts @@ -1,9 +1,10 @@ import {unimplemented} from '../../facade/exceptions'; -import {ControlValueAccessor} from './control_value_accessor'; import {AbstractControlDirective} from './abstract_control_directive'; +import {ControlValueAccessor} from './control_value_accessor'; import {AsyncValidatorFn, ValidatorFn} from './validators'; + /** * A base class that all control directive extend. * It binds a {@link Control} object to a DOM element. diff --git a/modules/@angular/common/src/forms/directives/ng_control_group.ts b/modules/@angular/common/src/forms/directives/ng_control_group.ts index 5b80b72555..9a5fcdbf8c 100644 --- a/modules/@angular/common/src/forms/directives/ng_control_group.ts +++ b/modules/@angular/common/src/forms/directives/ng_control_group.ts @@ -1,19 +1,11 @@ -import { - OnInit, - OnDestroy, - Directive, - Optional, - Inject, - Host, - SkipSelf, - forwardRef, - Self -} from '@angular/core'; -import {ControlContainer} from './control_container'; -import {controlPath, composeValidators, composeAsyncValidators} from './shared'; +import {Directive, Host, Inject, OnDestroy, OnInit, Optional, Self, SkipSelf, forwardRef} from '@angular/core'; + import {ControlGroup} from '../model'; +import {NG_ASYNC_VALIDATORS, NG_VALIDATORS} from '../validators'; + +import {ControlContainer} from './control_container'; import {Form} from './form_interface'; -import {NG_VALIDATORS, NG_ASYNC_VALIDATORS} from '../validators'; +import {composeAsyncValidators, composeValidators, controlPath} from './shared'; import {AsyncValidatorFn, ValidatorFn} from './validators'; export const controlGroupProvider: any = @@ -79,9 +71,10 @@ export class NgControlGroup extends ControlContainer implements OnInit, /** @internal */ _parent: ControlContainer; - constructor(@Host() @SkipSelf() parent: ControlContainer, - @Optional() @Self() @Inject(NG_VALIDATORS) private _validators: any[], - @Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: any[]) { + constructor( + @Host() @SkipSelf() parent: ControlContainer, + @Optional() @Self() @Inject(NG_VALIDATORS) private _validators: any[], + @Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: any[]) { super(); this._parent = parent; } diff --git a/modules/@angular/common/src/forms/directives/ng_control_name.ts b/modules/@angular/common/src/forms/directives/ng_control_name.ts index 48a481bc2b..a59f145bd3 100644 --- a/modules/@angular/common/src/forms/directives/ng_control_name.ts +++ b/modules/@angular/common/src/forms/directives/ng_control_name.ts @@ -1,30 +1,14 @@ -import { - OnChanges, - OnDestroy, - SimpleChanges, - Directive, - forwardRef, - Host, - SkipSelf, - Inject, - Optional, - Self -} from '@angular/core'; +import {Directive, Host, Inject, OnChanges, OnDestroy, Optional, Self, SimpleChanges, SkipSelf, forwardRef} from '@angular/core'; import {EventEmitter, ObservableWrapper} from '../../facade/async'; -import {ControlContainer} from './control_container'; -import {NgControl} from './ng_control'; -import {ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor'; -import { - controlPath, - composeValidators, - composeAsyncValidators, - isPropertyUpdated, - selectValueAccessor -} from './shared'; import {Control} from '../model'; -import {NG_VALIDATORS, NG_ASYNC_VALIDATORS} from '../validators'; -import {ValidatorFn, AsyncValidatorFn} from './validators'; +import {NG_ASYNC_VALIDATORS, NG_VALIDATORS} from '../validators'; + +import {ControlContainer} from './control_container'; +import {ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor'; +import {NgControl} from './ng_control'; +import {composeAsyncValidators, composeValidators, controlPath, isPropertyUpdated, selectValueAccessor} from './shared'; +import {AsyncValidatorFn, ValidatorFn} from './validators'; export const controlNameBinding: any = @@ -112,35 +96,37 @@ export class NgControlName extends NgControl implements OnChanges, /* Array */ any[], @Optional() @Self() @Inject(NG_VALUE_ACCESSOR) valueAccessors: ControlValueAccessor[]) { - super(); - this.valueAccessor = selectValueAccessor(this, valueAccessors); - } + super(); + this.valueAccessor = selectValueAccessor(this, valueAccessors); + } - ngOnChanges(changes: SimpleChanges) { - if (!this._added) { - this.formDirective.addControl(this); - this._added = true; - } - if (isPropertyUpdated(changes, this.viewModel)) { - this.viewModel = this.model; - this.formDirective.updateModel(this, this.model); - } - } + ngOnChanges(changes: SimpleChanges) { + if (!this._added) { + this.formDirective.addControl(this); + this._added = true; + } + if (isPropertyUpdated(changes, this.viewModel)) { + this.viewModel = this.model; + this.formDirective.updateModel(this, this.model); + } + } - ngOnDestroy(): void { this.formDirective.removeControl(this); } + ngOnDestroy(): void { this.formDirective.removeControl(this); } - viewToModelUpdate(newValue: any): void { - this.viewModel = newValue; - ObservableWrapper.callEmit(this.update, newValue); - } + viewToModelUpdate(newValue: any): void { + this.viewModel = newValue; + ObservableWrapper.callEmit(this.update, newValue); + } - get path(): string[] { return controlPath(this.name, this._parent); } + get path(): string[] { return controlPath(this.name, this._parent); } - get formDirective(): any { return this._parent.formDirective; } + get formDirective(): any { return this._parent.formDirective; } - get validator(): ValidatorFn { return composeValidators(this._validators); } + get validator(): ValidatorFn { return composeValidators(this._validators); } - get asyncValidator(): AsyncValidatorFn { return composeAsyncValidators(this._asyncValidators); } + get asyncValidator(): AsyncValidatorFn { + return composeAsyncValidators(this._asyncValidators); + } - get control(): Control { return this.formDirective.getControl(this); } + get control(): Control { return this.formDirective.getControl(this); } } diff --git a/modules/@angular/common/src/forms/directives/ng_control_status.ts b/modules/@angular/common/src/forms/directives/ng_control_status.ts index 5f29cc6adb..2b1b1a323c 100644 --- a/modules/@angular/common/src/forms/directives/ng_control_status.ts +++ b/modules/@angular/common/src/forms/directives/ng_control_status.ts @@ -1,7 +1,10 @@ import {Directive, Self} from '@angular/core'; -import {NgControl} from './ng_control'; + import {isPresent} from '../../facade/lang'; +import {NgControl} from './ng_control'; + + /** * Directive automatically applied to Angular forms that sets CSS classes * based on control status (valid/invalid/dirty/etc). diff --git a/modules/@angular/common/src/forms/directives/ng_form.ts b/modules/@angular/common/src/forms/directives/ng_form.ts index dfd20788c7..71f2773f7f 100644 --- a/modules/@angular/common/src/forms/directives/ng_form.ts +++ b/modules/@angular/common/src/forms/directives/ng_form.ts @@ -1,18 +1,16 @@ -import {Directive, forwardRef, Optional, Inject, Self} from '@angular/core'; -import { - PromiseWrapper, - ObservableWrapper, - EventEmitter -} from '../../facade/async'; +import {Directive, Inject, Optional, Self, forwardRef} from '@angular/core'; + +import {EventEmitter, ObservableWrapper, PromiseWrapper} from '../../facade/async'; import {ListWrapper} from '../../facade/collection'; import {isPresent} from '../../facade/lang'; -import {NgControl} from './ng_control'; -import {Form} from './form_interface'; -import {NgControlGroup} from './ng_control_group'; +import {AbstractControl, Control, ControlGroup} from '../model'; +import {NG_ASYNC_VALIDATORS, NG_VALIDATORS} from '../validators'; + import {ControlContainer} from './control_container'; -import {AbstractControl, ControlGroup, Control} from '../model'; -import {setUpControl, setUpControlGroup, composeValidators, composeAsyncValidators} from './shared'; -import {NG_VALIDATORS, NG_ASYNC_VALIDATORS} from '../validators'; +import {Form} from './form_interface'; +import {NgControl} from './ng_control'; +import {NgControlGroup} from './ng_control_group'; +import {composeAsyncValidators, composeValidators, setUpControl, setUpControlGroup} from './shared'; export const formDirectiveProvider: any = /*@ts2dart_const*/ {provide: ControlContainer, useExisting: forwardRef(() => NgForm)}; @@ -93,11 +91,12 @@ export class NgForm extends ControlContainer implements Form { form: ControlGroup; ngSubmit = new EventEmitter(); - constructor(@Optional() @Self() @Inject(NG_VALIDATORS) validators: any[], - @Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) asyncValidators: any[]) { + constructor( + @Optional() @Self() @Inject(NG_VALIDATORS) validators: any[], + @Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) asyncValidators: any[]) { super(); - this.form = new ControlGroup({}, null, composeValidators(validators), - composeAsyncValidators(asyncValidators)); + this.form = new ControlGroup( + {}, null, composeValidators(validators), composeAsyncValidators(asyncValidators)); } get submitted(): boolean { return this._submitted; } diff --git a/modules/@angular/common/src/forms/directives/ng_form_control.ts b/modules/@angular/common/src/forms/directives/ng_form_control.ts index 17b9885079..4c2bf28ddd 100644 --- a/modules/@angular/common/src/forms/directives/ng_form_control.ts +++ b/modules/@angular/common/src/forms/directives/ng_form_control.ts @@ -1,28 +1,14 @@ -import { - OnChanges, - SimpleChanges, - Directive, - forwardRef, - Inject, - Optional, - Self -} from '@angular/core'; +import {Directive, Inject, OnChanges, Optional, Self, SimpleChanges, forwardRef} from '@angular/core'; -import {StringMapWrapper} from '../../facade/collection'; import {EventEmitter, ObservableWrapper} from '../../facade/async'; - -import {NgControl} from './ng_control'; +import {StringMapWrapper} from '../../facade/collection'; import {Control} from '../model'; -import {NG_VALIDATORS, NG_ASYNC_VALIDATORS} from '../validators'; +import {NG_ASYNC_VALIDATORS, NG_VALIDATORS} from '../validators'; + import {ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor'; -import { - setUpControl, - composeValidators, - composeAsyncValidators, - isPropertyUpdated, - selectValueAccessor -} from './shared'; -import {ValidatorFn, AsyncValidatorFn} from './validators'; +import {NgControl} from './ng_control'; +import {composeAsyncValidators, composeValidators, isPropertyUpdated, selectValueAccessor, setUpControl} from './shared'; +import {AsyncValidatorFn, ValidatorFn} from './validators'; export const formControlBinding: any = /*@ts2dart_const*/ /* @ts2dart_Provider */ { @@ -98,35 +84,37 @@ export class NgFormControl extends NgControl implements OnChanges { /* Array */ any[], @Optional() @Self() @Inject(NG_VALUE_ACCESSOR) valueAccessors: ControlValueAccessor[]) { - super(); - this.valueAccessor = selectValueAccessor(this, valueAccessors); - } + super(); + this.valueAccessor = selectValueAccessor(this, valueAccessors); + } - ngOnChanges(changes: SimpleChanges): void { - if (this._isControlChanged(changes)) { - setUpControl(this.form, this); - this.form.updateValueAndValidity({emitEvent: false}); - } - if (isPropertyUpdated(changes, this.viewModel)) { - this.form.updateValue(this.model); - this.viewModel = this.model; - } - } + ngOnChanges(changes: SimpleChanges): void { + if (this._isControlChanged(changes)) { + setUpControl(this.form, this); + this.form.updateValueAndValidity({emitEvent: false}); + } + if (isPropertyUpdated(changes, this.viewModel)) { + this.form.updateValue(this.model); + this.viewModel = this.model; + } + } - get path(): string[] { return []; } + get path(): string[] { return []; } - get validator(): ValidatorFn { return composeValidators(this._validators); } + get validator(): ValidatorFn { return composeValidators(this._validators); } - get asyncValidator(): AsyncValidatorFn { return composeAsyncValidators(this._asyncValidators); } + get asyncValidator(): AsyncValidatorFn { + return composeAsyncValidators(this._asyncValidators); + } - get control(): Control { return this.form; } + get control(): Control { return this.form; } - viewToModelUpdate(newValue: any): void { - this.viewModel = newValue; - ObservableWrapper.callEmit(this.update, newValue); - } + viewToModelUpdate(newValue: any): void { + this.viewModel = newValue; + ObservableWrapper.callEmit(this.update, newValue); + } - private _isControlChanged(changes: {[key: string]: any}): boolean { - return StringMapWrapper.contains(changes, "form"); - } + private _isControlChanged(changes: {[key: string]: any}): boolean { + return StringMapWrapper.contains(changes, 'form'); + } } diff --git a/modules/@angular/common/src/forms/directives/ng_form_model.ts b/modules/@angular/common/src/forms/directives/ng_form_model.ts index 9b68180830..30b0669280 100644 --- a/modules/@angular/common/src/forms/directives/ng_form_model.ts +++ b/modules/@angular/common/src/forms/directives/ng_form_model.ts @@ -1,23 +1,17 @@ -import { - SimpleChanges, - OnChanges, - Directive, - forwardRef, - Inject, - Optional, - Self -} from '@angular/core'; -import {isBlank} from '../../facade/lang'; +import {Directive, Inject, OnChanges, Optional, Self, SimpleChanges, forwardRef} from '@angular/core'; + +import {EventEmitter, ObservableWrapper} from '../../facade/async'; import {ListWrapper, StringMapWrapper} from '../../facade/collection'; import {BaseException} from '../../facade/exceptions'; -import {ObservableWrapper, EventEmitter} from '../../facade/async'; -import {NgControl} from './ng_control'; -import {NgControlGroup} from './ng_control_group'; +import {isBlank} from '../../facade/lang'; +import {Control, ControlGroup} from '../model'; +import {NG_ASYNC_VALIDATORS, NG_VALIDATORS, Validators} from '../validators'; + import {ControlContainer} from './control_container'; import {Form} from './form_interface'; -import {Control, ControlGroup} from '../model'; -import {setUpControl, setUpControlGroup, composeValidators, composeAsyncValidators} from './shared'; -import {Validators, NG_VALIDATORS, NG_ASYNC_VALIDATORS} from '../validators'; +import {NgControl} from './ng_control'; +import {NgControlGroup} from './ng_control_group'; +import {composeAsyncValidators, composeValidators, setUpControl, setUpControlGroup} from './shared'; export const formDirectiveProvider: any = /*@ts2dart_const*/ /* @ts2dart_Provider */ { @@ -115,14 +109,15 @@ export class NgFormModel extends ControlContainer implements Form, directives: NgControl[] = []; ngSubmit = new EventEmitter(); - constructor(@Optional() @Self() @Inject(NG_VALIDATORS) private _validators: any[], - @Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: any[]) { + constructor( + @Optional() @Self() @Inject(NG_VALIDATORS) private _validators: any[], + @Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: any[]) { super(); } ngOnChanges(changes: SimpleChanges): void { this._checkFormPresent(); - if (StringMapWrapper.contains(changes, "form")) { + if (StringMapWrapper.contains(changes, 'form')) { var sync = composeValidators(this._validators); this.form.validator = Validators.compose([this.form.validator, sync]); diff --git a/modules/@angular/common/src/forms/directives/ng_model.ts b/modules/@angular/common/src/forms/directives/ng_model.ts index ae84f28871..a5205903e4 100644 --- a/modules/@angular/common/src/forms/directives/ng_model.ts +++ b/modules/@angular/common/src/forms/directives/ng_model.ts @@ -1,25 +1,13 @@ -import { - OnChanges, - SimpleChanges, - Directive, - forwardRef, - Inject, - Optional, - Self -} from '@angular/core'; +import {Directive, Inject, OnChanges, Optional, Self, SimpleChanges, forwardRef} from '@angular/core'; + import {EventEmitter, ObservableWrapper} from '../../facade/async'; +import {Control} from '../model'; +import {NG_ASYNC_VALIDATORS, NG_VALIDATORS} from '../validators'; + import {ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor'; import {NgControl} from './ng_control'; -import {Control} from '../model'; -import {NG_VALIDATORS, NG_ASYNC_VALIDATORS} from '../validators'; -import { - setUpControl, - isPropertyUpdated, - selectValueAccessor, - composeValidators, - composeAsyncValidators -} from './shared'; -import {ValidatorFn, AsyncValidatorFn} from './validators'; +import {composeAsyncValidators, composeValidators, isPropertyUpdated, selectValueAccessor, setUpControl} from './shared'; +import {AsyncValidatorFn, ValidatorFn} from './validators'; export const formControlBinding: any = /*@ts2dart_const*/ /* @ts2dart_Provider */ { @@ -70,33 +58,35 @@ export class NgModel extends NgControl implements OnChanges { @Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: any[], @Optional() @Self() @Inject(NG_VALUE_ACCESSOR) valueAccessors: ControlValueAccessor[]) { - super(); - this.valueAccessor = selectValueAccessor(this, valueAccessors); - } + super(); + this.valueAccessor = selectValueAccessor(this, valueAccessors); + } - ngOnChanges(changes: SimpleChanges) { - if (!this._added) { - setUpControl(this._control, this); - this._control.updateValueAndValidity({emitEvent: false}); - this._added = true; - } + ngOnChanges(changes: SimpleChanges) { + if (!this._added) { + setUpControl(this._control, this); + this._control.updateValueAndValidity({emitEvent: false}); + this._added = true; + } - if (isPropertyUpdated(changes, this.viewModel)) { - this._control.updateValue(this.model); - this.viewModel = this.model; - } - } + if (isPropertyUpdated(changes, this.viewModel)) { + this._control.updateValue(this.model); + this.viewModel = this.model; + } + } - get control(): Control { return this._control; } + get control(): Control { return this._control; } - get path(): string[] { return []; } + get path(): string[] { return []; } - get validator(): ValidatorFn { return composeValidators(this._validators); } + get validator(): ValidatorFn { return composeValidators(this._validators); } - get asyncValidator(): AsyncValidatorFn { return composeAsyncValidators(this._asyncValidators); } + get asyncValidator(): AsyncValidatorFn { + return composeAsyncValidators(this._asyncValidators); + } - viewToModelUpdate(newValue: any): void { - this.viewModel = newValue; - ObservableWrapper.callEmit(this.update, newValue); - } + viewToModelUpdate(newValue: any): void { + this.viewModel = newValue; + ObservableWrapper.callEmit(this.update, newValue); + } } diff --git a/modules/@angular/common/src/forms/directives/normalize_validator.ts b/modules/@angular/common/src/forms/directives/normalize_validator.ts index c956c8d4ae..d669b78961 100644 --- a/modules/@angular/common/src/forms/directives/normalize_validator.ts +++ b/modules/@angular/common/src/forms/directives/normalize_validator.ts @@ -1,5 +1,6 @@ import {AbstractControl} from '../model'; -import {Validator, ValidatorFn, AsyncValidatorFn} from './validators'; + +import {AsyncValidatorFn, Validator, ValidatorFn} from './validators'; export function normalizeValidator(validator: ValidatorFn | Validator): ValidatorFn { if ((validator).validate !== undefined) { diff --git a/modules/@angular/common/src/forms/directives/number_value_accessor.ts b/modules/@angular/common/src/forms/directives/number_value_accessor.ts index ca84ed50af..d5a9763dfa 100644 --- a/modules/@angular/common/src/forms/directives/number_value_accessor.ts +++ b/modules/@angular/common/src/forms/directives/number_value_accessor.ts @@ -1,6 +1,8 @@ import {Directive, ElementRef, Renderer, forwardRef} from '@angular/core'; + import {NumberWrapper} from '../../facade/lang'; -import {NG_VALUE_ACCESSOR, ControlValueAccessor} from './control_value_accessor'; + +import {ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor'; export const NUMBER_VALUE_ACCESSOR: any = /*@ts2dart_const*/ /*@ts2dart_Provider*/ { provide: NG_VALUE_ACCESSOR, diff --git a/modules/@angular/common/src/forms/directives/radio_control_value_accessor.ts b/modules/@angular/common/src/forms/directives/radio_control_value_accessor.ts index f87656f195..c74b0433ae 100644 --- a/modules/@angular/common/src/forms/directives/radio_control_value_accessor.ts +++ b/modules/@angular/common/src/forms/directives/radio_control_value_accessor.ts @@ -1,17 +1,9 @@ -import { - Directive, - ElementRef, - Renderer, - forwardRef, - Input, - OnInit, - OnDestroy, - Injector, - Injectable -} from '@angular/core'; -import {isPresent} from '../../facade/lang'; +import {Directive, ElementRef, Injectable, Injector, Input, OnDestroy, OnInit, Renderer, forwardRef} from '@angular/core'; + import {ListWrapper} from '../../facade/collection'; -import {NG_VALUE_ACCESSOR, ControlValueAccessor} from './control_value_accessor'; +import {isPresent} from '../../facade/lang'; + +import {ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor'; import {NgControl} from './ng_control'; export const RADIO_VALUE_ACCESSOR: any = /*@ts2dart_const*/ /*@ts2dart_Provider*/ { @@ -49,10 +41,10 @@ export class RadioControlRegistry { }); } - private _isSameGroup(controlPair:[NgControl, RadioControlValueAccessor], - accessor: RadioControlValueAccessor) { + private _isSameGroup( + controlPair: [NgControl, RadioControlValueAccessor], accessor: RadioControlValueAccessor) { return controlPair[0].control.root === accessor._control.control.root && - controlPair[1].name === accessor.name; + controlPair[1].name === accessor.name; } } @@ -102,8 +94,9 @@ export class RadioControlValueAccessor implements ControlValueAccessor, onChange = () => {}; onTouched = () => {}; - constructor(private _renderer: Renderer, private _elementRef: ElementRef, - private _registry: RadioControlRegistry, private _injector: Injector) {} + constructor( + private _renderer: Renderer, private _elementRef: ElementRef, + private _registry: RadioControlRegistry, private _injector: Injector) {} ngOnInit(): void { this._control = this._injector.get(NgControl); diff --git a/modules/@angular/common/src/forms/directives/select_control_value_accessor.ts b/modules/@angular/common/src/forms/directives/select_control_value_accessor.ts index 4ba6d0061b..265f8994da 100644 --- a/modules/@angular/common/src/forms/directives/select_control_value_accessor.ts +++ b/modules/@angular/common/src/forms/directives/select_control_value_accessor.ts @@ -1,23 +1,9 @@ -import { - Directive, - Renderer, - forwardRef, - ElementRef, - Input, - Host, - OnDestroy, - Optional -} from '@angular/core'; -import { - StringWrapper, - isPrimitive, - isPresent, - isBlank, - looseIdentical -} from '../../facade/lang'; -import {MapWrapper} from '../../facade/collection'; +import {Directive, ElementRef, Host, Input, OnDestroy, Optional, Renderer, forwardRef} from '@angular/core'; -import {NG_VALUE_ACCESSOR, ControlValueAccessor} from './control_value_accessor'; +import {MapWrapper} from '../../facade/collection'; +import {StringWrapper, isBlank, isPresent, isPrimitive, looseIdentical} from '../../facade/lang'; + +import {ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor'; export const SELECT_VALUE_ACCESSOR: any = /*@ts2dart_const*/ /*@ts2dart_Provider*/ { provide: NG_VALUE_ACCESSOR, @@ -27,12 +13,12 @@ export const SELECT_VALUE_ACCESSOR: any = /*@ts2dart_const*/ /*@ts2dart_Provider function _buildValueString(id: string, value: any): string { if (isBlank(id)) return `${value}`; - if (!isPrimitive(value)) value = "Object"; + if (!isPrimitive(value)) value = 'Object'; return StringWrapper.slice(`${id}: ${value}`, 0, 50); } function _extractId(valueString: string): string { - return valueString.split(":")[0]; + return valueString.split(':')[0]; } /** @@ -112,8 +98,9 @@ export class SelectControlValueAccessor implements ControlValueAccessor { export class NgSelectOption implements OnDestroy { id: string; - constructor(private _element: ElementRef, private _renderer: Renderer, - @Optional() @Host() private _select: SelectControlValueAccessor) { + constructor( + private _element: ElementRef, private _renderer: Renderer, + @Optional() @Host() private _select: SelectControlValueAccessor) { if (isPresent(this._select)) this.id = this._select._registerOption(); } diff --git a/modules/@angular/common/src/forms/directives/select_multiple_control_value_accessor.ts b/modules/@angular/common/src/forms/directives/select_multiple_control_value_accessor.ts index f2f981ebb3..4e39059d9f 100644 --- a/modules/@angular/common/src/forms/directives/select_multiple_control_value_accessor.ts +++ b/modules/@angular/common/src/forms/directives/select_multiple_control_value_accessor.ts @@ -1,23 +1,9 @@ -import { - Input, - Directive, - ElementRef, - Renderer, - Optional, - Host, - OnDestroy, - forwardRef -} from "@angular/core"; -import { - isBlank, - isPrimitive, - StringWrapper, - isPresent, - looseIdentical, - isString -} from '../../facade/lang'; -import {ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor'; +import {Directive, ElementRef, Host, Input, OnDestroy, Optional, Renderer, forwardRef} from '@angular/core'; + import {MapWrapper} from '../../facade/collection'; +import {StringWrapper, isBlank, isPresent, isPrimitive, isString, looseIdentical} from '../../facade/lang'; + +import {ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor'; const SELECT_MULTIPLE_VALUE_ACCESSOR = { provide: NG_VALUE_ACCESSOR, @@ -28,12 +14,12 @@ const SELECT_MULTIPLE_VALUE_ACCESSOR = { function _buildValueString(id: string, value: any): string { if (isBlank(id)) return `${value}`; if (isString(value)) value = `'${value}'`; - if (!isPrimitive(value)) value = "Object"; + if (!isPrimitive(value)) value = 'Object'; return StringWrapper.slice(`${id}: ${value}`, 0, 50); } function _extractId(valueString: string): string { - return valueString.split(":")[0]; + return valueString.split(':')[0]; } /** Mock interface for HTML Options */ @@ -74,9 +60,7 @@ export class SelectMultipleControlValueAccessor implements ControlValueAccessor let values: Array = >value; // convert values to ids let ids = values.map((v) => this._getOptionId(v)); - this._optionMap.forEach((opt, o) => { - opt._setSelected(ids.indexOf(o.toString()) > -1); - }); + this._optionMap.forEach((opt, o) => { opt._setSelected(ids.indexOf(o.toString()) > -1); }); } registerOnChange(fn: (value: any) => any): void { @@ -108,7 +92,7 @@ export class SelectMultipleControlValueAccessor implements ControlValueAccessor /** @internal */ _registerOption(value: NgSelectMultipleOption): string { - let id:string = (this._idCounter++).toString(); + let id: string = (this._idCounter++).toString(); this._optionMap.set(id, value); return id; } @@ -145,8 +129,9 @@ export class NgSelectMultipleOption implements OnDestroy { /** @internal */ _value: any; - constructor(private _element: ElementRef, private _renderer: Renderer, - @Optional() @Host() private _select: SelectMultipleControlValueAccessor) { + constructor( + private _element: ElementRef, private _renderer: Renderer, + @Optional() @Host() private _select: SelectMultipleControlValueAccessor) { if (isPresent(this._select)) { this.id = this._select._registerOption(this); } diff --git a/modules/@angular/common/src/forms/directives/shared.ts b/modules/@angular/common/src/forms/directives/shared.ts index 8baceaf856..8d300e82e8 100644 --- a/modules/@angular/common/src/forms/directives/shared.ts +++ b/modules/@angular/common/src/forms/directives/shared.ts @@ -1,21 +1,21 @@ import {ListWrapper, StringMapWrapper} from '../../facade/collection'; -import {isBlank, isPresent, looseIdentical, hasConstructor} from '../../facade/lang'; import {BaseException} from '../../facade/exceptions'; - -import {ControlContainer} from './control_container'; -import {NgControl} from './ng_control'; -import {AbstractControlDirective} from './abstract_control_directive'; -import {NgControlGroup} from './ng_control_group'; +import {hasConstructor, isBlank, isPresent, looseIdentical} from '../../facade/lang'; import {Control, ControlGroup} from '../model'; import {Validators} from '../validators'; + +import {AbstractControlDirective} from './abstract_control_directive'; +import {CheckboxControlValueAccessor} from './checkbox_value_accessor'; +import {ControlContainer} from './control_container'; import {ControlValueAccessor} from './control_value_accessor'; import {DefaultValueAccessor} from './default_value_accessor'; +import {NgControl} from './ng_control'; +import {NgControlGroup} from './ng_control_group'; +import {normalizeAsyncValidator, normalizeValidator} from './normalize_validator'; import {NumberValueAccessor} from './number_value_accessor'; -import {CheckboxControlValueAccessor} from './checkbox_value_accessor'; -import {SelectControlValueAccessor} from './select_control_value_accessor'; import {RadioControlValueAccessor} from './radio_control_value_accessor'; -import {normalizeValidator, normalizeAsyncValidator} from './normalize_validator'; -import {ValidatorFn, AsyncValidatorFn} from './validators'; +import {SelectControlValueAccessor} from './select_control_value_accessor'; +import {AsyncValidatorFn, ValidatorFn} from './validators'; export function controlPath(name: string, parent: ControlContainer): string[] { @@ -25,8 +25,8 @@ export function controlPath(name: string, parent: ControlContainer): string[] { } export function setUpControl(control: Control, dir: NgControl): void { - if (isBlank(control)) _throwError(dir, "Cannot find control"); - if (isBlank(dir.valueAccessor)) _throwError(dir, "No value accessor for"); + if (isBlank(control)) _throwError(dir, 'Cannot find control'); + if (isBlank(dir.valueAccessor)) _throwError(dir, 'No value accessor for'); control.validator = Validators.compose([control.validator, dir.validator]); control.asyncValidator = Validators.composeAsync([control.asyncValidator, dir.asyncValidator]); @@ -47,13 +47,13 @@ export function setUpControl(control: Control, dir: NgControl): void { } export function setUpControlGroup(control: ControlGroup, dir: NgControlGroup) { - if (isBlank(control)) _throwError(dir, "Cannot find control"); + if (isBlank(control)) _throwError(dir, 'Cannot find control'); control.validator = Validators.compose([control.validator, dir.validator]); control.asyncValidator = Validators.composeAsync([control.asyncValidator, dir.asyncValidator]); } function _throwError(dir: AbstractControlDirective, message: string): void { - var path = dir.path.join(" -> "); + var path = dir.path.join(' -> '); throw new BaseException(`${message} '${path}'`); } @@ -61,23 +61,23 @@ export function composeValidators(validators: /* Array */ an return isPresent(validators) ? Validators.compose(validators.map(normalizeValidator)) : null; } -export function composeAsyncValidators( - validators: /* Array */ any[]): AsyncValidatorFn { +export function composeAsyncValidators(validators: /* Array */ any[]): + AsyncValidatorFn { return isPresent(validators) ? Validators.composeAsync(validators.map(normalizeAsyncValidator)) : null; } export function isPropertyUpdated(changes: {[key: string]: any}, viewModel: any): boolean { - if (!StringMapWrapper.contains(changes, "model")) return false; - var change = changes["model"]; + if (!StringMapWrapper.contains(changes, 'model')) return false; + var change = changes['model']; if (change.isFirstChange()) return true; return !looseIdentical(viewModel, change.currentValue); } // TODO: vsavkin remove it once https://github.com/angular/angular/issues/3011 is implemented -export function selectValueAccessor(dir: NgControl, - valueAccessors: ControlValueAccessor[]): ControlValueAccessor { +export function selectValueAccessor( + dir: NgControl, valueAccessors: ControlValueAccessor[]): ControlValueAccessor { if (isBlank(valueAccessors)) return null; var defaultAccessor: ControlValueAccessor; @@ -87,17 +87,17 @@ export function selectValueAccessor(dir: NgControl, if (hasConstructor(v, DefaultValueAccessor)) { defaultAccessor = v; - } else if (hasConstructor(v, CheckboxControlValueAccessor) || - hasConstructor(v, NumberValueAccessor) || - hasConstructor(v, SelectControlValueAccessor) || - hasConstructor(v, RadioControlValueAccessor)) { + } else if ( + hasConstructor(v, CheckboxControlValueAccessor) || hasConstructor(v, NumberValueAccessor) || + hasConstructor(v, SelectControlValueAccessor) || + hasConstructor(v, RadioControlValueAccessor)) { if (isPresent(builtinAccessor)) - _throwError(dir, "More than one built-in value accessor matches"); + _throwError(dir, 'More than one built-in value accessor matches'); builtinAccessor = v; } else { if (isPresent(customAccessor)) - _throwError(dir, "More than one custom value accessor matches"); + _throwError(dir, 'More than one custom value accessor matches'); customAccessor = v; } }); @@ -106,6 +106,6 @@ export function selectValueAccessor(dir: NgControl, if (isPresent(builtinAccessor)) return builtinAccessor; if (isPresent(defaultAccessor)) return defaultAccessor; - _throwError(dir, "No valid value accessor for"); + _throwError(dir, 'No valid value accessor for'); return null; } diff --git a/modules/@angular/common/src/forms/directives/validators.ts b/modules/@angular/common/src/forms/directives/validators.ts index 0e60918edd..401941f8f8 100644 --- a/modules/@angular/common/src/forms/directives/validators.ts +++ b/modules/@angular/common/src/forms/directives/validators.ts @@ -1,7 +1,8 @@ -import {forwardRef, Attribute, Directive} from '@angular/core'; +import {Attribute, Directive, forwardRef} from '@angular/core'; + import {NumberWrapper} from '../../facade/lang'; -import {Validators, NG_VALIDATORS} from '../validators'; import {AbstractControl} from '../model'; +import {NG_VALIDATORS, Validators} from '../validators'; @@ -82,7 +83,7 @@ export const MIN_LENGTH_VALIDATOR: any = /*@ts2dart_const*/ /*@ts2dart_Provider* export class MinLengthValidator implements Validator { private _validator: ValidatorFn; - constructor(@Attribute("minlength") minLength: string) { + constructor(@Attribute('minlength') minLength: string) { this._validator = Validators.minLength(NumberWrapper.parseInt(minLength, 10)); } @@ -115,7 +116,7 @@ export const MAX_LENGTH_VALIDATOR: any = /*@ts2dart_const*/ /*@ts2dart_Provider* export class MaxLengthValidator implements Validator { private _validator: ValidatorFn; - constructor(@Attribute("maxlength") maxLength: string) { + constructor(@Attribute('maxlength') maxLength: string) { this._validator = Validators.maxLength(NumberWrapper.parseInt(maxLength, 10)); } @@ -150,7 +151,7 @@ export const PATTERN_VALIDATOR: any = /*@ts2dart_const*/ /*@ts2dart_Provider*/ { export class PatternValidator implements Validator { private _validator: ValidatorFn; - constructor(@Attribute("pattern") pattern: string) { + constructor(@Attribute('pattern') pattern: string) { this._validator = Validators.pattern(pattern); } diff --git a/modules/@angular/common/src/forms/form_builder.ts b/modules/@angular/common/src/forms/form_builder.ts index b388606c76..5289d1cd09 100644 --- a/modules/@angular/common/src/forms/form_builder.ts +++ b/modules/@angular/common/src/forms/form_builder.ts @@ -1,8 +1,11 @@ import {Injectable} from '@angular/core'; + import {StringMapWrapper} from '../facade/collection'; -import {isPresent, isArray} from '../facade/lang'; +import {isArray, isPresent} from '../facade/lang'; + +import {AsyncValidatorFn, ValidatorFn} from './directives/validators'; import * as modelModule from './model'; -import {ValidatorFn, AsyncValidatorFn} from './directives/validators'; + /** @@ -56,21 +59,21 @@ export class FormBuilder { * * See the {@link ControlGroup} constructor for more details. */ - group(controlsConfig: {[key: string]: any}, - extra: {[key: string]: any} = null): modelModule.ControlGroup { + group(controlsConfig: {[key: string]: any}, extra: {[key: string]: any} = null): + modelModule.ControlGroup { var controls = this._reduceControls(controlsConfig); var optionals = <{[key: string]: boolean}>( - isPresent(extra) ? StringMapWrapper.get(extra, "optionals") : null); - var validator: ValidatorFn = isPresent(extra) ? StringMapWrapper.get(extra, "validator") : null; + isPresent(extra) ? StringMapWrapper.get(extra, 'optionals') : null); + var validator: ValidatorFn = isPresent(extra) ? StringMapWrapper.get(extra, 'validator') : null; var asyncValidator: AsyncValidatorFn = - isPresent(extra) ? StringMapWrapper.get(extra, "asyncValidator") : null; + isPresent(extra) ? StringMapWrapper.get(extra, 'asyncValidator') : null; return new modelModule.ControlGroup(controls, optionals, validator, asyncValidator); } /** * Construct a new {@link Control} with the given `value`,`validator`, and `asyncValidator`. */ - control(value: Object, validator: ValidatorFn = null, - asyncValidator: AsyncValidatorFn = null): modelModule.Control { + control(value: Object, validator: ValidatorFn = null, asyncValidator: AsyncValidatorFn = null): + modelModule.Control { return new modelModule.Control(value, validator, asyncValidator); } @@ -78,15 +81,16 @@ export class FormBuilder { * Construct an array of {@link Control}s from the given `controlsConfig` array of * configuration, with the given optional `validator` and `asyncValidator`. */ - array(controlsConfig: any[], validator: ValidatorFn = null, - asyncValidator: AsyncValidatorFn = null): modelModule.ControlArray { + array( + controlsConfig: any[], validator: ValidatorFn = null, + asyncValidator: AsyncValidatorFn = null): modelModule.ControlArray { var controls = controlsConfig.map(c => this._createControl(c)); return new modelModule.ControlArray(controls, validator, asyncValidator); } /** @internal */ - _reduceControls(controlsConfig: {[k: string]: - any}): {[key: string]: modelModule.AbstractControl} { + _reduceControls(controlsConfig: {[k: string]: any}): + {[key: string]: modelModule.AbstractControl} { var controls: {[key: string]: modelModule.AbstractControl} = {}; StringMapWrapper.forEach(controlsConfig, (controlConfig: any, controlName: string) => { controls[controlName] = this._createControl(controlConfig); diff --git a/modules/@angular/common/src/forms/model.ts b/modules/@angular/common/src/forms/model.ts index 3741d2e079..b0151e09db 100644 --- a/modules/@angular/common/src/forms/model.ts +++ b/modules/@angular/common/src/forms/model.ts @@ -1,48 +1,49 @@ -import {isPresent, isBlank, normalizeBool} from '../facade/lang'; -import {Observable, EventEmitter, ObservableWrapper} from '../facade/async'; +import {EventEmitter, Observable, ObservableWrapper} from '../facade/async'; +import {ListWrapper, StringMapWrapper} from '../facade/collection'; +import {isBlank, isPresent, normalizeBool} from '../facade/lang'; import {PromiseWrapper} from '../facade/promise'; -import {StringMapWrapper, ListWrapper} from '../facade/collection'; -import {ValidatorFn, AsyncValidatorFn} from './directives/validators'; + +import {AsyncValidatorFn, ValidatorFn} from './directives/validators'; + /** * Indicates that a Control is valid, i.e. that no errors exist in the input value. */ -export const VALID = "VALID"; +export const VALID = 'VALID'; /** * Indicates that a Control is invalid, i.e. that an error exists in the input value. */ -export const INVALID = "INVALID"; +export const INVALID = 'INVALID'; /** * Indicates that a Control is pending, i.e. that async validation is occurring and * errors are not yet available for the input value. */ -export const PENDING = "PENDING"; +export const PENDING = 'PENDING'; export function isControl(control: Object): boolean { return control instanceof AbstractControl; } -function _find(control: AbstractControl, path: Array| string) { +function _find(control: AbstractControl, path: Array| string) { if (isBlank(path)) return null; if (!(path instanceof Array)) { - path = (path).split("/"); + path = (path).split('/'); } if (path instanceof Array && ListWrapper.isEmpty(path)) return null; - return (>path) - .reduce((v, name) => { - if (v instanceof ControlGroup) { - return isPresent(v.controls[name]) ? v.controls[name] : null; - } else if (v instanceof ControlArray) { - var index = name; - return isPresent(v.at(index)) ? v.at(index) : null; - } else { - return null; - } - }, control); + return (>path).reduce((v, name) => { + if (v instanceof ControlGroup) { + return isPresent(v.controls[name]) ? v.controls[name] : null; + } else if (v instanceof ControlArray) { + var index = name; + return isPresent(v.at(index)) ? v.at(index) : null; + } else { + return null; + } + }, control); } function toObservable(r: any): Observable { @@ -62,7 +63,7 @@ export abstract class AbstractControl { private _errors: {[key: string]: any}; private _pristine: boolean = true; private _touched: boolean = false; - private _parent: ControlGroup | ControlArray; + private _parent: ControlGroup|ControlArray; private _asyncValidationSubscription: any; constructor(public validator: ValidatorFn, public asyncValidator: AsyncValidatorFn) {} @@ -112,10 +113,10 @@ export abstract class AbstractControl { } } - setParent(parent: ControlGroup | ControlArray): void { this._parent = parent; } + setParent(parent: ControlGroup|ControlArray): void { this._parent = parent; } - updateValueAndValidity( - {onlySelf, emitEvent}: {onlySelf?: boolean, emitEvent?: boolean} = {}): void { + updateValueAndValidity({onlySelf, emitEvent}: {onlySelf?: boolean, emitEvent?: boolean} = {}): + void { onlySelf = normalizeBool(onlySelf); emitEvent = isPresent(emitEvent) ? emitEvent : true; @@ -196,7 +197,7 @@ export abstract class AbstractControl { } } - find(path: Array| string): AbstractControl { return _find(this, path); } + find(path: Array|string): AbstractControl { return _find(this, path); } getError(errorCode: string, path: string[] = null): any { var control = isPresent(path) && !ListWrapper.isEmpty(path) ? this.find(path) : this; @@ -273,8 +274,8 @@ export class Control extends AbstractControl { /** @internal */ _onChange: Function; - constructor(value: any = null, validator: ValidatorFn = null, - asyncValidator: AsyncValidatorFn = null) { + constructor( + value: any = null, validator: ValidatorFn = null, asyncValidator: AsyncValidatorFn = null) { super(validator, asyncValidator); this._value = value; this.updateValueAndValidity({onlySelf: true, emitEvent: false}); @@ -339,9 +340,9 @@ export class Control extends AbstractControl { export class ControlGroup extends AbstractControl { private _optionals: {[key: string]: boolean}; - constructor(public controls: {[key: string]: AbstractControl}, - optionals: {[key: string]: boolean} = null, validator: ValidatorFn = null, - asyncValidator: AsyncValidatorFn = null) { + constructor( + public controls: {[key: string]: AbstractControl}, optionals: {[key: string]: boolean} = null, + validator: ValidatorFn = null, asyncValidator: AsyncValidatorFn = null) { super(validator, asyncValidator); this._optionals = isPresent(optionals) ? optionals : {}; this._initObservables(); @@ -467,8 +468,9 @@ export class ControlGroup extends AbstractControl { * @experimental */ export class ControlArray extends AbstractControl { - constructor(public controls: AbstractControl[], validator: ValidatorFn = null, - asyncValidator: AsyncValidatorFn = null) { + constructor( + public controls: AbstractControl[], validator: ValidatorFn = null, + asyncValidator: AsyncValidatorFn = null) { super(validator, asyncValidator); this._initObservables(); this._setParentForControls(); diff --git a/modules/@angular/common/src/forms/validators.ts b/modules/@angular/common/src/forms/validators.ts index 0be2d8a321..b1958da086 100644 --- a/modules/@angular/common/src/forms/validators.ts +++ b/modules/@angular/common/src/forms/validators.ts @@ -1,10 +1,13 @@ import {OpaqueToken} from '@angular/core'; -import {isBlank, isPresent, isString} from '../facade/lang'; -import {PromiseWrapper} from '../facade/promise'; + import {ObservableWrapper} from '../facade/async'; import {StringMapWrapper} from '../facade/collection'; +import {isBlank, isPresent, isString} from '../facade/lang'; +import {PromiseWrapper} from '../facade/promise'; + +import {AsyncValidatorFn, ValidatorFn} from './directives/validators'; import * as modelModule from './model'; -import {ValidatorFn, AsyncValidatorFn} from './directives/validators'; + /** * Providers for validators to be used for {@link Control}s in a form. @@ -16,7 +19,7 @@ import {ValidatorFn, AsyncValidatorFn} from './directives/validators'; * {@example core/forms/ts/ng_validators/ng_validators.ts region='ng_validators'} * @experimental */ -export const NG_VALIDATORS: OpaqueToken = /*@ts2dart_const*/ new OpaqueToken("NgValidators"); +export const NG_VALIDATORS: OpaqueToken = /*@ts2dart_const*/ new OpaqueToken('NgValidators'); /** * Providers for asynchronous validators to be used for {@link Control}s @@ -29,7 +32,7 @@ export const NG_VALIDATORS: OpaqueToken = /*@ts2dart_const*/ new OpaqueToken("Ng * @experimental */ export const NG_ASYNC_VALIDATORS: OpaqueToken = - /*@ts2dart_const*/ new OpaqueToken("NgAsyncValidators"); + /*@ts2dart_const*/ new OpaqueToken('NgAsyncValidators'); /** * Provides a set of validators used by form controls. @@ -50,9 +53,9 @@ export class Validators { * Validator that requires controls to have a non-empty value. */ static required(control: modelModule.AbstractControl): {[key: string]: boolean} { - return isBlank(control.value) || (isString(control.value) && control.value == "") ? - {"required": true} : - null; + return isBlank(control.value) || (isString(control.value) && control.value == '') ? + {'required': true} : + null; } /** @@ -63,8 +66,8 @@ export class Validators { if (isPresent(Validators.required(control))) return null; var v: string = control.value; return v.length < minLength ? - {"minlength": {"requiredLength": minLength, "actualLength": v.length}} : - null; + {'minlength': {'requiredLength': minLength, 'actualLength': v.length}} : + null; }; } @@ -76,8 +79,8 @@ export class Validators { if (isPresent(Validators.required(control))) return null; var v: string = control.value; return v.length > maxLength ? - {"maxlength": {"requiredLength": maxLength, "actualLength": v.length}} : - null; + {'maxlength': {'requiredLength': maxLength, 'actualLength': v.length}} : + null; }; } @@ -90,7 +93,7 @@ export class Validators { let regex = new RegExp(`^${pattern}$`); let v: string = control.value; return regex.test(v) ? null : - {"pattern": {"requiredPattern": `^${pattern}$`, "actualValue": v}}; + {'pattern': {'requiredPattern': `^${pattern}$`, 'actualValue': v}}; }; } @@ -129,13 +132,13 @@ function _convertToPromise(obj: any): any { return PromiseWrapper.isPromise(obj) ? obj : ObservableWrapper.toPromise(obj); } -function _executeValidators(control: modelModule.AbstractControl, - validators: ValidatorFn[]): any[] { +function _executeValidators( + control: modelModule.AbstractControl, validators: ValidatorFn[]): any[] { return validators.map(v => v(control)); } -function _executeAsyncValidators(control: modelModule.AbstractControl, - validators: AsyncValidatorFn[]): any[] { +function _executeAsyncValidators( + control: modelModule.AbstractControl, validators: AsyncValidatorFn[]): any[] { return validators.map(v => v(control)); } diff --git a/modules/@angular/common/src/location/hash_location_strategy.ts b/modules/@angular/common/src/location/hash_location_strategy.ts index c08a7407da..c3cca2f4b3 100644 --- a/modules/@angular/common/src/location/hash_location_strategy.ts +++ b/modules/@angular/common/src/location/hash_location_strategy.ts @@ -1,9 +1,11 @@ -import {Injectable, Inject, Optional} from '@angular/core'; +import {Inject, Injectable, Optional} from '@angular/core'; + import {isPresent} from '../facade/lang'; -import {LocationStrategy, APP_BASE_HREF} from './location_strategy'; import {Location} from './location'; -import {UrlChangeListener, PlatformLocation} from './platform_location'; +import {APP_BASE_HREF, LocationStrategy} from './location_strategy'; +import {PlatformLocation, UrlChangeListener} from './platform_location'; + /** @@ -51,8 +53,9 @@ import {UrlChangeListener, PlatformLocation} from './platform_location'; @Injectable() export class HashLocationStrategy extends LocationStrategy { private _baseHref: string = ''; - constructor(private _platformLocation: PlatformLocation, - @Optional() @Inject(APP_BASE_HREF) _baseHref?: string) { + constructor( + private _platformLocation: PlatformLocation, + @Optional() @Inject(APP_BASE_HREF) _baseHref?: string) { super(); if (isPresent(_baseHref)) { this._baseHref = _baseHref; diff --git a/modules/@angular/common/src/location/location.ts b/modules/@angular/common/src/location/location.ts index 52e653ce8f..41d9541aec 100644 --- a/modules/@angular/common/src/location/location.ts +++ b/modules/@angular/common/src/location/location.ts @@ -1,8 +1,10 @@ -import {Injectable, EventEmitter} from '@angular/core'; +import {EventEmitter, Injectable} from '@angular/core'; + import {ObservableWrapper} from '../facade/async'; import {LocationStrategy} from './location_strategy'; + /** * `Location` is a service that applications can use to interact with a browser's URL. * Depending on which {@link LocationStrategy} is used, `Location` will either persist @@ -127,8 +129,9 @@ export class Location { /** * Subscribe to the platform's `popState` events. */ - subscribe(onNext: (value: any) => void, onThrow: (exception: any) => void = null, - onReturn: () => void = null): Object { + subscribe( + onNext: (value: any) => void, onThrow: (exception: any) => void = null, + onReturn: () => void = null): Object { return ObservableWrapper.subscribe(this._subject, onNext, onThrow, onReturn); } diff --git a/modules/@angular/common/src/location/path_location_strategy.ts b/modules/@angular/common/src/location/path_location_strategy.ts index 5ca9f5da7d..a6902105b2 100644 --- a/modules/@angular/common/src/location/path_location_strategy.ts +++ b/modules/@angular/common/src/location/path_location_strategy.ts @@ -1,10 +1,12 @@ -import {Injectable, Inject, Optional} from '@angular/core'; -import {isBlank} from '../facade/lang'; -import {BaseException} from '../facade/exceptions'; +import {Inject, Injectable, Optional} from '@angular/core'; + +import {BaseException} from '../facade/exceptions'; +import {isBlank} from '../facade/lang'; -import {PlatformLocation, UrlChangeListener} from './platform_location'; -import {LocationStrategy, APP_BASE_HREF} from './location_strategy'; import {Location} from './location'; +import {APP_BASE_HREF, LocationStrategy} from './location_strategy'; +import {PlatformLocation, UrlChangeListener} from './platform_location'; + /** * `PathLocationStrategy` is a {@link LocationStrategy} used to configure the @@ -60,8 +62,9 @@ import {Location} from './location'; export class PathLocationStrategy extends LocationStrategy { private _baseHref: string; - constructor(private _platformLocation: PlatformLocation, - @Optional() @Inject(APP_BASE_HREF) href?: string) { + constructor( + private _platformLocation: PlatformLocation, + @Optional() @Inject(APP_BASE_HREF) href?: string) { super(); if (isBlank(href)) { @@ -89,7 +92,7 @@ export class PathLocationStrategy extends LocationStrategy { path(): string { return this._platformLocation.pathname + - Location.normalizeQueryParams(this._platformLocation.search); + Location.normalizeQueryParams(this._platformLocation.search); } pushState(state: any, title: string, url: string, queryParams: string) { diff --git a/modules/@angular/common/src/pipes.ts b/modules/@angular/common/src/pipes.ts index 972a1105ca..796d2a2a04 100644 --- a/modules/@angular/common/src/pipes.ts +++ b/modules/@angular/common/src/pipes.ts @@ -5,13 +5,13 @@ */ export {AsyncPipe} from './pipes/async_pipe'; +export {COMMON_PIPES} from './pipes/common_pipes'; export {DatePipe} from './pipes/date_pipe'; -export {JsonPipe} from './pipes/json_pipe'; -export {SlicePipe} from './pipes/slice_pipe'; -export {LowerCasePipe} from './pipes/lowercase_pipe'; -export {DecimalPipe, PercentPipe, CurrencyPipe} from './pipes/number_pipe'; -export {UpperCasePipe} from './pipes/uppercase_pipe'; -export {ReplacePipe} from './pipes/replace_pipe'; export {I18nPluralPipe} from './pipes/i18n_plural_pipe'; export {I18nSelectPipe} from './pipes/i18n_select_pipe'; -export {COMMON_PIPES} from './pipes/common_pipes'; +export {JsonPipe} from './pipes/json_pipe'; +export {LowerCasePipe} from './pipes/lowercase_pipe'; +export {CurrencyPipe, DecimalPipe, PercentPipe} from './pipes/number_pipe'; +export {ReplacePipe} from './pipes/replace_pipe'; +export {SlicePipe} from './pipes/slice_pipe'; +export {UpperCasePipe} from './pipes/uppercase_pipe'; diff --git a/modules/@angular/common/src/pipes/async_pipe.ts b/modules/@angular/common/src/pipes/async_pipe.ts index 62307ca8fc..8a0f0ee9a3 100644 --- a/modules/@angular/common/src/pipes/async_pipe.ts +++ b/modules/@angular/common/src/pipes/async_pipe.ts @@ -1,7 +1,7 @@ -import {Pipe, Injectable, ChangeDetectorRef, OnDestroy, WrappedValue} from '@angular/core'; +import {ChangeDetectorRef, Injectable, OnDestroy, Pipe, WrappedValue} from '@angular/core'; +import {EventEmitter, Observable, ObservableWrapper} from '../facade/async'; import {isBlank, isPresent, isPromise} from '../facade/lang'; -import {ObservableWrapper, Observable, EventEmitter} from '../facade/async'; import {InvalidPipeArgumentException} from './invalid_pipe_argument_exception'; @@ -13,7 +13,7 @@ interface SubscriptionStrategy { class ObservableStrategy implements SubscriptionStrategy { createSubscription(async: any, updateLatestValue: any): any { - return ObservableWrapper.subscribe(async, updateLatestValue, e => { throw e; } ); + return ObservableWrapper.subscribe(async, updateLatestValue, e => { throw e; }); } dispose(subscription: any): void { ObservableWrapper.dispose(subscription); } @@ -73,7 +73,7 @@ export class AsyncPipe implements OnDestroy { /** @internal */ _subscription: Object = null; /** @internal */ - _obj: Observable| Promise| EventEmitter = null; + _obj: Observable|Promise|EventEmitter = null; /** @internal */ _ref: ChangeDetectorRef; private _strategy: SubscriptionStrategy = null; @@ -86,7 +86,7 @@ export class AsyncPipe implements OnDestroy { } } - transform(obj: Observable| Promise| EventEmitter): any { + transform(obj: Observable|Promise|EventEmitter): any { if (isBlank(this._obj)) { if (isPresent(obj)) { this._subscribe(obj); @@ -109,7 +109,7 @@ export class AsyncPipe implements OnDestroy { } /** @internal */ - _subscribe(obj: Observable| Promise| EventEmitter): void { + _subscribe(obj: Observable|Promise|EventEmitter): void { this._obj = obj; this._strategy = this._selectStrategy(obj); this._subscription = this._strategy.createSubscription( @@ -117,7 +117,7 @@ export class AsyncPipe implements OnDestroy { } /** @internal */ - _selectStrategy(obj: Observable| Promise| EventEmitter): any { + _selectStrategy(obj: Observable|Promise|EventEmitter): any { if (isPromise(obj)) { return _promiseStrategy; } else if (ObservableWrapper.isObservable(obj)) { diff --git a/modules/@angular/common/src/pipes/common_pipes.ts b/modules/@angular/common/src/pipes/common_pipes.ts index 5964b1e8c1..d013e17ab6 100644 --- a/modules/@angular/common/src/pipes/common_pipes.ts +++ b/modules/@angular/common/src/pipes/common_pipes.ts @@ -4,15 +4,16 @@ * This module provides a set of common Pipes. */ import {AsyncPipe} from './async_pipe'; -import {UpperCasePipe} from './uppercase_pipe'; -import {LowerCasePipe} from './lowercase_pipe'; -import {JsonPipe} from './json_pipe'; -import {SlicePipe} from './slice_pipe'; import {DatePipe} from './date_pipe'; -import {DecimalPipe, PercentPipe, CurrencyPipe} from './number_pipe'; -import {ReplacePipe} from './replace_pipe'; import {I18nPluralPipe} from './i18n_plural_pipe'; import {I18nSelectPipe} from './i18n_select_pipe'; +import {JsonPipe} from './json_pipe'; +import {LowerCasePipe} from './lowercase_pipe'; +import {CurrencyPipe, DecimalPipe, PercentPipe} from './number_pipe'; +import {ReplacePipe} from './replace_pipe'; +import {SlicePipe} from './slice_pipe'; +import {UpperCasePipe} from './uppercase_pipe'; + /** * A collection of Angular core pipes that are likely to be used in each and every @@ -35,5 +36,5 @@ export const COMMON_PIPES = /*@ts2dart_const*/[ DatePipe, ReplacePipe, I18nPluralPipe, - I18nSelectPipe + I18nSelectPipe, ]; diff --git a/modules/@angular/common/src/pipes/date_pipe.ts b/modules/@angular/common/src/pipes/date_pipe.ts index c8f9e97593..d93ceb3aec 100644 --- a/modules/@angular/common/src/pipes/date_pipe.ts +++ b/modules/@angular/common/src/pipes/date_pipe.ts @@ -1,11 +1,6 @@ -import {PipeTransform, Pipe, Injectable} from '@angular/core'; -import { - isDate, - isNumber, - isString, - DateWrapper, - isBlank, -} from '../facade/lang'; +import {Injectable, Pipe, PipeTransform} from '@angular/core'; + +import {isDate, isNumber, isString, DateWrapper, isBlank,} from '../facade/lang'; import {DateFormatter} from '../facade/intl'; import {StringMapWrapper} from '../facade/collection'; diff --git a/modules/@angular/common/src/pipes/i18n_plural_pipe.ts b/modules/@angular/common/src/pipes/i18n_plural_pipe.ts index 83049a28ec..2ec8d40c22 100644 --- a/modules/@angular/common/src/pipes/i18n_plural_pipe.ts +++ b/modules/@angular/common/src/pipes/i18n_plural_pipe.ts @@ -1,5 +1,7 @@ -import {PipeTransform, Pipe} from '@angular/core'; -import {isStringMap, StringWrapper, isPresent, RegExpWrapper} from '../facade/lang'; +import {Pipe, PipeTransform} from '@angular/core'; + +import {RegExpWrapper, StringWrapper, isPresent, isStringMap} from '../facade/lang'; + import {InvalidPipeArgumentException} from './invalid_pipe_argument_exception'; var interpolationExp: RegExp = RegExpWrapper.create('#'); diff --git a/modules/@angular/common/src/pipes/i18n_select_pipe.ts b/modules/@angular/common/src/pipes/i18n_select_pipe.ts index 6c7f498eb8..d9c66b6210 100644 --- a/modules/@angular/common/src/pipes/i18n_select_pipe.ts +++ b/modules/@angular/common/src/pipes/i18n_select_pipe.ts @@ -1,8 +1,11 @@ -import {PipeTransform, Pipe} from '@angular/core'; -import {isStringMap} from '../facade/lang'; +import {Pipe, PipeTransform} from '@angular/core'; + import {StringMapWrapper} from '../facade/collection'; +import {isStringMap} from '../facade/lang'; + import {InvalidPipeArgumentException} from './invalid_pipe_argument_exception'; + /** * * Generic selector that displays the string that matches the current value. diff --git a/modules/@angular/common/src/pipes/invalid_pipe_argument_exception.ts b/modules/@angular/common/src/pipes/invalid_pipe_argument_exception.ts index f4bcfcfb93..8d2b82b861 100644 --- a/modules/@angular/common/src/pipes/invalid_pipe_argument_exception.ts +++ b/modules/@angular/common/src/pipes/invalid_pipe_argument_exception.ts @@ -1,5 +1,5 @@ -import {Type, stringify} from '../facade/lang'; import {BaseException} from '../facade/exceptions'; +import {Type, stringify} from '../facade/lang'; export class InvalidPipeArgumentException extends BaseException { constructor(type: Type, value: Object) { diff --git a/modules/@angular/common/src/pipes/json_pipe.ts b/modules/@angular/common/src/pipes/json_pipe.ts index 8eefa4715f..d9d75d3dc2 100644 --- a/modules/@angular/common/src/pipes/json_pipe.ts +++ b/modules/@angular/common/src/pipes/json_pipe.ts @@ -1,7 +1,9 @@ -import {PipeTransform, Pipe} from '@angular/core'; +import {Pipe, PipeTransform} from '@angular/core'; + import {Json} from '../facade/lang'; + /** * Transforms any input value using `JSON.stringify`. Useful for debugging. * diff --git a/modules/@angular/common/src/pipes/lowercase_pipe.ts b/modules/@angular/common/src/pipes/lowercase_pipe.ts index 300cf99d79..817345174d 100644 --- a/modules/@angular/common/src/pipes/lowercase_pipe.ts +++ b/modules/@angular/common/src/pipes/lowercase_pipe.ts @@ -1,7 +1,10 @@ -import {PipeTransform, Pipe} from '@angular/core'; -import {isString, isBlank} from '../facade/lang'; +import {Pipe, PipeTransform} from '@angular/core'; + +import {isBlank, isString} from '../facade/lang'; + import {InvalidPipeArgumentException} from './invalid_pipe_argument_exception'; + /** * Transforms text to lowercase. * diff --git a/modules/@angular/common/src/pipes/number_pipe.ts b/modules/@angular/common/src/pipes/number_pipe.ts index b243543b51..094467d8ca 100644 --- a/modules/@angular/common/src/pipes/number_pipe.ts +++ b/modules/@angular/common/src/pipes/number_pipe.ts @@ -1,15 +1,8 @@ -import {PipeTransform, Pipe} from '@angular/core'; +import {Pipe, PipeTransform} from '@angular/core'; -import { - isNumber, - isPresent, - isBlank, - NumberWrapper, - RegExpWrapper, - Type -} from '../facade/lang'; import {BaseException} from '../facade/exceptions'; -import {NumberFormatter, NumberFormatStyle} from '../facade/intl'; +import {NumberFormatStyle, NumberFormatter} from '../facade/intl'; +import {NumberWrapper, RegExpWrapper, Type, isBlank, isNumber, isPresent} from '../facade/lang'; import {InvalidPipeArgumentException} from './invalid_pipe_argument_exception'; @@ -19,8 +12,9 @@ var _re = RegExpWrapper.create('^(\\d+)?\\.((\\d+)(\\-(\\d+))?)?$'); /** * Internal function to format numbers used by Decimal, Percent and Date pipes. */ -function formatNumber(pipe: Type, value: number, style: NumberFormatStyle, digits: string, currency: string = null, - currencyAsSymbol: boolean = false): string { +function formatNumber( + pipe: Type, value: number, style: NumberFormatStyle, digits: string, currency: string = null, + currencyAsSymbol: boolean = false): string { if (isBlank(value)) return null; if (!isNumber(value)) { throw new InvalidPipeArgumentException(pipe, value); @@ -138,9 +132,10 @@ export class PercentPipe implements PipeTransform { */ @Pipe({name: 'currency'}) export class CurrencyPipe implements PipeTransform { - transform(value: any, currencyCode: string = 'USD', symbolDisplay: boolean = false, - digits: string = null): string { - return formatNumber(CurrencyPipe, value, NumberFormatStyle.Currency, digits, currencyCode, - symbolDisplay); + transform( + value: any, currencyCode: string = 'USD', symbolDisplay: boolean = false, + digits: string = null): string { + return formatNumber( + CurrencyPipe, value, NumberFormatStyle.Currency, digits, currencyCode, symbolDisplay); } } diff --git a/modules/@angular/common/src/pipes/replace_pipe.ts b/modules/@angular/common/src/pipes/replace_pipe.ts index 5fbcf12a5c..62efbb75fb 100644 --- a/modules/@angular/common/src/pipes/replace_pipe.ts +++ b/modules/@angular/common/src/pipes/replace_pipe.ts @@ -1,13 +1,6 @@ -import {Injectable, PipeTransform, Pipe} from '@angular/core'; +import {Injectable, Pipe, PipeTransform} from '@angular/core'; -import { - isBlank, - isString, - isNumber, - isFunction, - RegExpWrapper, - StringWrapper -} from '../facade/lang'; +import {RegExpWrapper, StringWrapper, isBlank, isFunction, isNumber, isString} from '../facade/lang'; import {InvalidPipeArgumentException} from './invalid_pipe_argument_exception'; @@ -44,7 +37,7 @@ import {InvalidPipeArgumentException} from './invalid_pipe_argument_exception'; @Pipe({name: 'replace'}) @Injectable() export class ReplacePipe implements PipeTransform { - transform(value: any, pattern: string | RegExp, replacement: Function | string): any { + transform(value: any, pattern: string|RegExp, replacement: Function|string): any { if (isBlank(value)) { return value; } diff --git a/modules/@angular/common/src/pipes/slice_pipe.ts b/modules/@angular/common/src/pipes/slice_pipe.ts index b03b269d89..2270b97ce5 100644 --- a/modules/@angular/common/src/pipes/slice_pipe.ts +++ b/modules/@angular/common/src/pipes/slice_pipe.ts @@ -1,6 +1,7 @@ -import {PipeTransform, Pipe} from '@angular/core'; -import {isBlank, isString, isArray, StringWrapper} from '../facade/lang'; +import {Pipe, PipeTransform} from '@angular/core'; + import {ListWrapper} from '../facade/collection'; +import {StringWrapper, isArray, isBlank, isString} from '../facade/lang'; import {InvalidPipeArgumentException} from './invalid_pipe_argument_exception'; diff --git a/modules/@angular/common/src/pipes/uppercase_pipe.ts b/modules/@angular/common/src/pipes/uppercase_pipe.ts index 0dfc883c1a..01d11f93dd 100644 --- a/modules/@angular/common/src/pipes/uppercase_pipe.ts +++ b/modules/@angular/common/src/pipes/uppercase_pipe.ts @@ -1,7 +1,10 @@ -import {PipeTransform, Pipe} from '@angular/core'; -import {isString, isBlank} from '../facade/lang'; +import {Pipe, PipeTransform} from '@angular/core'; + +import {isBlank, isString} from '../facade/lang'; + import {InvalidPipeArgumentException} from './invalid_pipe_argument_exception'; + /** * Implements uppercase transforms to text. * diff --git a/modules/@angular/common/test/directives/ng_class_spec.ts b/modules/@angular/common/test/directives/ng_class_spec.ts index 1545a43b1a..0dbb5d7557 100644 --- a/modules/@angular/common/test/directives/ng_class_spec.ts +++ b/modules/@angular/common/test/directives/ng_class_spec.ts @@ -1,15 +1,4 @@ -import { - beforeEach, - beforeEachProviders, - ddescribe, - xdescribe, - describe, - expect, - iit, - inject, - it, - xit, -} from '@angular/core/testing/testing_internal'; +import {beforeEach, beforeEachProviders, ddescribe, xdescribe, describe, expect, iit, inject, it, xit,} from '@angular/core/testing/testing_internal'; import {ComponentFixture, TestComponentBuilder} from '@angular/compiler/testing'; import {AsyncTestCompleter} from '@angular/core/testing/testing_internal'; import {ListWrapper, StringMapWrapper, SetWrapper} from '../../src/facade/collection'; @@ -25,499 +14,564 @@ export function main() { describe('binding to CSS class list', () => { it('should clean up when the directive is destroyed', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - var template = '
'; - tcb.overrideTemplate(TestComponent, template) - .createAsync(TestComponent) - .then((fixture) => { - fixture.debugElement.componentInstance.items = [['0']]; - fixture.detectChanges(); - fixture.debugElement.componentInstance.items = [['1']]; + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + var template = '
'; + tcb.overrideTemplate(TestComponent, template) + .createAsync(TestComponent) + .then((fixture) => { + fixture.debugElement.componentInstance.items = [['0']]; + fixture.detectChanges(); + fixture.debugElement.componentInstance.items = [['1']]; - detectChangesAndCheck(fixture, '1'); + detectChangesAndCheck(fixture, '1'); - async.done(); - }); - })); + async.done(); + }); + })); describe('expressions evaluating to objects', () => { it('should add classes specified in an object literal', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - var template = '
'; + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + var template = '
'; - tcb.overrideTemplate(TestComponent, template) - .createAsync(TestComponent) - .then((fixture) => { - detectChangesAndCheck(fixture, 'foo'); - async.done(); - }); - })); + tcb.overrideTemplate(TestComponent, template) + .createAsync(TestComponent) + .then((fixture) => { + detectChangesAndCheck(fixture, 'foo'); + async.done(); + }); + })); it('should add classes specified in an object literal without change in class names', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - var template = `
`; + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + var template = `
`; - tcb.overrideTemplate(TestComponent, template) - .createAsync(TestComponent) - .then((fixture) => { - detectChangesAndCheck(fixture, 'foo-bar fooBar'); - async.done(); - }); - })); + tcb.overrideTemplate(TestComponent, template) + .createAsync(TestComponent) + .then((fixture) => { + detectChangesAndCheck(fixture, 'foo-bar fooBar'); + async.done(); + }); + })); it('should add and remove classes based on changes in object literal values', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - var template = '
'; + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + var template = '
'; - tcb.overrideTemplate(TestComponent, template) - .createAsync(TestComponent) - .then((fixture) => { - detectChangesAndCheck(fixture, 'foo'); + tcb.overrideTemplate(TestComponent, template) + .createAsync(TestComponent) + .then((fixture) => { + detectChangesAndCheck(fixture, 'foo'); - fixture.debugElement.componentInstance.condition = false; - detectChangesAndCheck(fixture, 'bar'); + fixture.debugElement.componentInstance.condition = false; + detectChangesAndCheck(fixture, 'bar'); - async.done(); - }); - })); + async.done(); + }); + })); it('should add and remove classes based on changes to the expression object', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - var template = '
'; + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + var template = '
'; - tcb.overrideTemplate(TestComponent, template) - .createAsync(TestComponent) - .then((fixture) => { - detectChangesAndCheck(fixture, 'foo'); + tcb.overrideTemplate(TestComponent, template) + .createAsync(TestComponent) + .then((fixture) => { + detectChangesAndCheck(fixture, 'foo'); - StringMapWrapper.set(fixture.debugElement.componentInstance.objExpr, 'bar', true); - detectChangesAndCheck(fixture, 'foo bar'); + StringMapWrapper.set( + fixture.debugElement.componentInstance.objExpr, 'bar', true); + detectChangesAndCheck(fixture, 'foo bar'); - StringMapWrapper.set(fixture.debugElement.componentInstance.objExpr, 'baz', true); - detectChangesAndCheck(fixture, 'foo bar baz'); + StringMapWrapper.set( + fixture.debugElement.componentInstance.objExpr, 'baz', true); + detectChangesAndCheck(fixture, 'foo bar baz'); - StringMapWrapper.delete(fixture.debugElement.componentInstance.objExpr, 'bar'); - detectChangesAndCheck(fixture, 'foo baz'); + StringMapWrapper.delete(fixture.debugElement.componentInstance.objExpr, 'bar'); + detectChangesAndCheck(fixture, 'foo baz'); - async.done(); - }); - })); + async.done(); + }); + })); it('should add and remove classes based on reference changes to the expression object', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - var template = '
'; + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + var template = '
'; - tcb.overrideTemplate(TestComponent, template) - .createAsync(TestComponent) - .then((fixture) => { - detectChangesAndCheck(fixture, 'foo'); + tcb.overrideTemplate(TestComponent, template) + .createAsync(TestComponent) + .then((fixture) => { + detectChangesAndCheck(fixture, 'foo'); - fixture.debugElement.componentInstance.objExpr = {foo: true, bar: true}; - detectChangesAndCheck(fixture, 'foo bar'); + fixture.debugElement.componentInstance.objExpr = {foo: true, bar: true}; + detectChangesAndCheck(fixture, 'foo bar'); - fixture.debugElement.componentInstance.objExpr = {baz: true}; - detectChangesAndCheck(fixture, 'baz'); + fixture.debugElement.componentInstance.objExpr = {baz: true}; + detectChangesAndCheck(fixture, 'baz'); - async.done(); - }); - })); + async.done(); + }); + })); it('should remove active classes when expression evaluates to null', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - var template = '
'; + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + var template = '
'; - tcb.overrideTemplate(TestComponent, template) - .createAsync(TestComponent) - .then((fixture) => { - detectChangesAndCheck(fixture, 'foo'); + tcb.overrideTemplate(TestComponent, template) + .createAsync(TestComponent) + .then((fixture) => { + detectChangesAndCheck(fixture, 'foo'); - fixture.debugElement.componentInstance.objExpr = null; - detectChangesAndCheck(fixture, ''); + fixture.debugElement.componentInstance.objExpr = null; + detectChangesAndCheck(fixture, ''); - fixture.debugElement.componentInstance.objExpr = {'foo': false, 'bar': true}; - detectChangesAndCheck(fixture, 'bar'); + fixture.debugElement.componentInstance.objExpr = {'foo': false, 'bar': true}; + detectChangesAndCheck(fixture, 'bar'); - async.done(); - }); - })); + async.done(); + }); + })); it('should allow multiple classes per expression', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - var template = '
'; + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + var template = '
'; - tcb.overrideTemplate(TestComponent, template) - .createAsync(TestComponent) - .then((fixture) => { + tcb.overrideTemplate(TestComponent, template) + .createAsync(TestComponent) + .then((fixture) => { - fixture.debugElement.componentInstance.objExpr = { - 'bar baz': true, - 'bar1 baz1': true - }; - detectChangesAndCheck(fixture, 'bar baz bar1 baz1'); + fixture.debugElement.componentInstance.objExpr = { + 'bar baz': true, + 'bar1 baz1': true + }; + detectChangesAndCheck(fixture, 'bar baz bar1 baz1'); - fixture.debugElement.componentInstance.objExpr = { - 'bar baz': false, - 'bar1 baz1': true - }; - detectChangesAndCheck(fixture, 'bar1 baz1'); + fixture.debugElement.componentInstance.objExpr = { + 'bar baz': false, + 'bar1 baz1': true + }; + detectChangesAndCheck(fixture, 'bar1 baz1'); - async.done(); - }); - })); + async.done(); + }); + })); it('should split by one or more spaces between classes', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - var template = '
'; + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + var template = '
'; - tcb.overrideTemplate(TestComponent, template) - .createAsync(TestComponent) - .then((fixture) => { + tcb.overrideTemplate(TestComponent, template) + .createAsync(TestComponent) + .then((fixture) => { - fixture.debugElement.componentInstance.objExpr = {'foo bar baz': true}; - detectChangesAndCheck(fixture, 'foo bar baz'); + fixture.debugElement.componentInstance.objExpr = {'foo bar baz': true}; + detectChangesAndCheck(fixture, 'foo bar baz'); - async.done(); - }); - })); + async.done(); + }); + })); }); describe('expressions evaluating to lists', () => { it('should add classes specified in a list literal', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - var template = `
`; + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + var template = `
`; - tcb.overrideTemplate(TestComponent, template) - .createAsync(TestComponent) - .then((fixture) => { - detectChangesAndCheck(fixture, 'foo bar foo-bar fooBar'); - async.done(); - }); - })); + tcb.overrideTemplate(TestComponent, template) + .createAsync(TestComponent) + .then((fixture) => { + detectChangesAndCheck(fixture, 'foo bar foo-bar fooBar'); + async.done(); + }); + })); it('should add and remove classes based on changes to the expression', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - var template = '
'; + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + var template = '
'; - tcb.overrideTemplate(TestComponent, template) - .createAsync(TestComponent) - .then((fixture) => { - var arrExpr: string[] = fixture.debugElement.componentInstance.arrExpr; - detectChangesAndCheck(fixture, 'foo'); + tcb.overrideTemplate(TestComponent, template) + .createAsync(TestComponent) + .then((fixture) => { + var arrExpr: string[] = fixture.debugElement.componentInstance.arrExpr; + detectChangesAndCheck(fixture, 'foo'); - arrExpr.push('bar'); - detectChangesAndCheck(fixture, 'foo bar'); + arrExpr.push('bar'); + detectChangesAndCheck(fixture, 'foo bar'); - arrExpr[1] = 'baz'; - detectChangesAndCheck(fixture, 'foo baz'); + arrExpr[1] = 'baz'; + detectChangesAndCheck(fixture, 'foo baz'); - ListWrapper.remove(fixture.debugElement.componentInstance.arrExpr, 'baz'); - detectChangesAndCheck(fixture, 'foo'); + ListWrapper.remove(fixture.debugElement.componentInstance.arrExpr, 'baz'); + detectChangesAndCheck(fixture, 'foo'); - async.done(); - }); - })); + async.done(); + }); + })); it('should add and remove classes when a reference changes', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - var template = '
'; + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + var template = '
'; - tcb.overrideTemplate(TestComponent, template) - .createAsync(TestComponent) - .then((fixture) => { - detectChangesAndCheck(fixture, 'foo'); + tcb.overrideTemplate(TestComponent, template) + .createAsync(TestComponent) + .then((fixture) => { + detectChangesAndCheck(fixture, 'foo'); - fixture.debugElement.componentInstance.arrExpr = ['bar']; - detectChangesAndCheck(fixture, 'bar'); + fixture.debugElement.componentInstance.arrExpr = ['bar']; + detectChangesAndCheck(fixture, 'bar'); - async.done(); - }); - })); + async.done(); + }); + })); it('should take initial classes into account when a reference changes', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - var template = '
'; + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + var template = '
'; - tcb.overrideTemplate(TestComponent, template) - .createAsync(TestComponent) - .then((fixture) => { - detectChangesAndCheck(fixture, 'foo'); + tcb.overrideTemplate(TestComponent, template) + .createAsync(TestComponent) + .then((fixture) => { + detectChangesAndCheck(fixture, 'foo'); - fixture.debugElement.componentInstance.arrExpr = ['bar']; - detectChangesAndCheck(fixture, 'foo bar'); + fixture.debugElement.componentInstance.arrExpr = ['bar']; + detectChangesAndCheck(fixture, 'foo bar'); - async.done(); - }); - })); + async.done(); + }); + })); it('should ignore empty or blank class names', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - var template = '
'; + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + var template = '
'; - tcb.overrideTemplate(TestComponent, template) - .createAsync(TestComponent) - .then((fixture) => { + tcb.overrideTemplate(TestComponent, template) + .createAsync(TestComponent) + .then((fixture) => { - fixture.debugElement.componentInstance.arrExpr = ['', ' ']; - detectChangesAndCheck(fixture, 'foo'); + fixture.debugElement.componentInstance.arrExpr = ['', ' ']; + detectChangesAndCheck(fixture, 'foo'); - async.done(); - }); - })); + async.done(); + }); + })); it('should trim blanks from class names', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - var template = '
'; + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + var template = '
'; - tcb.overrideTemplate(TestComponent, template) - .createAsync(TestComponent) - .then((fixture) => { + tcb.overrideTemplate(TestComponent, template) + .createAsync(TestComponent) + .then((fixture) => { - fixture.debugElement.componentInstance.arrExpr = [' bar ']; - detectChangesAndCheck(fixture, 'foo bar'); + fixture.debugElement.componentInstance.arrExpr = [' bar ']; + detectChangesAndCheck(fixture, 'foo bar'); - async.done(); - }); - })); + async.done(); + }); + })); it('should allow multiple classes per item in arrays', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - var template = '
'; + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + var template = '
'; - tcb.overrideTemplate(TestComponent, template) - .createAsync(TestComponent) - .then((fixture) => { + tcb.overrideTemplate(TestComponent, template) + .createAsync(TestComponent) + .then((fixture) => { - fixture.debugElement.componentInstance.arrExpr = - ['foo bar baz', 'foo1 bar1 baz1']; - detectChangesAndCheck(fixture, 'foo bar baz foo1 bar1 baz1'); + fixture.debugElement.componentInstance.arrExpr = + ['foo bar baz', 'foo1 bar1 baz1']; + detectChangesAndCheck(fixture, 'foo bar baz foo1 bar1 baz1'); - fixture.debugElement.componentInstance.arrExpr = ['foo bar baz foobar']; - detectChangesAndCheck(fixture, 'foo bar baz foobar'); + fixture.debugElement.componentInstance.arrExpr = ['foo bar baz foobar']; + detectChangesAndCheck(fixture, 'foo bar baz foobar'); - async.done(); - }); - })); + async.done(); + }); + })); }); describe('expressions evaluating to sets', () => { it('should add and remove classes if the set instance changed', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - var template = '
'; + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + var template = '
'; - tcb.overrideTemplate(TestComponent, template) - .createAsync(TestComponent) - .then((fixture) => { - var setExpr = new Set(); - setExpr.add('bar'); - fixture.debugElement.componentInstance.setExpr = setExpr; - detectChangesAndCheck(fixture, 'bar'); + tcb.overrideTemplate(TestComponent, template) + .createAsync(TestComponent) + .then((fixture) => { + var setExpr = new Set(); + setExpr.add('bar'); + fixture.debugElement.componentInstance.setExpr = setExpr; + detectChangesAndCheck(fixture, 'bar'); - setExpr = new Set(); - setExpr.add('baz'); - fixture.debugElement.componentInstance.setExpr = setExpr; - detectChangesAndCheck(fixture, 'baz'); + setExpr = new Set(); + setExpr.add('baz'); + fixture.debugElement.componentInstance.setExpr = setExpr; + detectChangesAndCheck(fixture, 'baz'); - async.done(); - }); - })); + async.done(); + }); + })); }); describe('expressions evaluating to string', () => { it('should add classes specified in a string literal', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - var template = `
`; + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + var template = `
`; - tcb.overrideTemplate(TestComponent, template) - .createAsync(TestComponent) - .then((fixture) => { - detectChangesAndCheck(fixture, 'foo bar foo-bar fooBar'); - async.done(); - }); - })); + tcb.overrideTemplate(TestComponent, template) + .createAsync(TestComponent) + .then((fixture) => { + detectChangesAndCheck(fixture, 'foo bar foo-bar fooBar'); + async.done(); + }); + })); it('should add and remove classes based on changes to the expression', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - var template = '
'; + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + var template = '
'; - tcb.overrideTemplate(TestComponent, template) - .createAsync(TestComponent) - .then((fixture) => { - detectChangesAndCheck(fixture, 'foo'); + tcb.overrideTemplate(TestComponent, template) + .createAsync(TestComponent) + .then((fixture) => { + detectChangesAndCheck(fixture, 'foo'); - fixture.debugElement.componentInstance.strExpr = 'foo bar'; - detectChangesAndCheck(fixture, 'foo bar'); + fixture.debugElement.componentInstance.strExpr = 'foo bar'; + detectChangesAndCheck(fixture, 'foo bar'); - fixture.debugElement.componentInstance.strExpr = 'baz'; - detectChangesAndCheck(fixture, 'baz'); + fixture.debugElement.componentInstance.strExpr = 'baz'; + detectChangesAndCheck(fixture, 'baz'); - async.done(); - }); - })); + async.done(); + }); + })); it('should remove active classes when switching from string to null', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - var template = `
`; + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + var template = `
`; - tcb.overrideTemplate(TestComponent, template) - .createAsync(TestComponent) - .then((fixture) => { - detectChangesAndCheck(fixture, 'foo'); + tcb.overrideTemplate(TestComponent, template) + .createAsync(TestComponent) + .then((fixture) => { + detectChangesAndCheck(fixture, 'foo'); - fixture.debugElement.componentInstance.strExpr = null; - detectChangesAndCheck(fixture, ''); + fixture.debugElement.componentInstance.strExpr = null; + detectChangesAndCheck(fixture, ''); - async.done(); - }); - })); + async.done(); + }); + })); it('should take initial classes into account when switching from string to null', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - var template = `
`; + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + var template = `
`; - tcb.overrideTemplate(TestComponent, template) - .createAsync(TestComponent) - .then((fixture) => { - detectChangesAndCheck(fixture, 'foo'); + tcb.overrideTemplate(TestComponent, template) + .createAsync(TestComponent) + .then((fixture) => { + detectChangesAndCheck(fixture, 'foo'); - fixture.debugElement.componentInstance.strExpr = null; - detectChangesAndCheck(fixture, 'foo'); + fixture.debugElement.componentInstance.strExpr = null; + detectChangesAndCheck(fixture, 'foo'); - async.done(); - }); - })); + async.done(); + }); + })); it('should ignore empty and blank strings', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - var template = `
`; + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + var template = `
`; - tcb.overrideTemplate(TestComponent, template) - .createAsync(TestComponent) - .then((fixture) => { - fixture.debugElement.componentInstance.strExpr = ''; - detectChangesAndCheck(fixture, 'foo'); + tcb.overrideTemplate(TestComponent, template) + .createAsync(TestComponent) + .then((fixture) => { + fixture.debugElement.componentInstance.strExpr = ''; + detectChangesAndCheck(fixture, 'foo'); - async.done(); - }); - })); + async.done(); + }); + })); }); describe('cooperation with other class-changing constructs', () => { it('should co-operate with the class attribute', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - var template = '
'; + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + var template = '
'; - tcb.overrideTemplate(TestComponent, template) - .createAsync(TestComponent) - .then((fixture) => { - StringMapWrapper.set(fixture.debugElement.componentInstance.objExpr, 'bar', true); - detectChangesAndCheck(fixture, 'init foo bar'); + tcb.overrideTemplate(TestComponent, template) + .createAsync(TestComponent) + .then((fixture) => { + StringMapWrapper.set( + fixture.debugElement.componentInstance.objExpr, 'bar', true); + detectChangesAndCheck(fixture, 'init foo bar'); - StringMapWrapper.set(fixture.debugElement.componentInstance.objExpr, 'foo', false); - detectChangesAndCheck(fixture, 'init bar'); + StringMapWrapper.set( + fixture.debugElement.componentInstance.objExpr, 'foo', false); + detectChangesAndCheck(fixture, 'init bar'); - fixture.debugElement.componentInstance.objExpr = null; - detectChangesAndCheck(fixture, 'init foo'); + fixture.debugElement.componentInstance.objExpr = null; + detectChangesAndCheck(fixture, 'init foo'); - async.done(); - }); - })); + async.done(); + }); + })); it('should co-operate with the interpolated class attribute', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - var template = `
`; + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + var template = `
`; - tcb.overrideTemplate(TestComponent, template) - .createAsync(TestComponent) - .then((fixture) => { - StringMapWrapper.set(fixture.debugElement.componentInstance.objExpr, 'bar', true); - detectChangesAndCheck(fixture, `init foo bar`); + tcb.overrideTemplate(TestComponent, template) + .createAsync(TestComponent) + .then((fixture) => { + StringMapWrapper.set( + fixture.debugElement.componentInstance.objExpr, 'bar', true); + detectChangesAndCheck(fixture, `init foo bar`); - StringMapWrapper.set(fixture.debugElement.componentInstance.objExpr, 'foo', false); - detectChangesAndCheck(fixture, `init bar`); + StringMapWrapper.set( + fixture.debugElement.componentInstance.objExpr, 'foo', false); + detectChangesAndCheck(fixture, `init bar`); - fixture.debugElement.componentInstance.objExpr = null; - detectChangesAndCheck(fixture, `init foo`); + fixture.debugElement.componentInstance.objExpr = null; + detectChangesAndCheck(fixture, `init foo`); - async.done(); - }); - })); + async.done(); + }); + })); it('should co-operate with the class attribute and binding to it', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - var template = `
`; + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + var template = `
`; - tcb.overrideTemplate(TestComponent, template) - .createAsync(TestComponent) - .then((fixture) => { - StringMapWrapper.set(fixture.debugElement.componentInstance.objExpr, 'bar', true); - detectChangesAndCheck(fixture, `init foo bar`); + tcb.overrideTemplate(TestComponent, template) + .createAsync(TestComponent) + .then((fixture) => { + StringMapWrapper.set( + fixture.debugElement.componentInstance.objExpr, 'bar', true); + detectChangesAndCheck(fixture, `init foo bar`); - StringMapWrapper.set(fixture.debugElement.componentInstance.objExpr, 'foo', false); - detectChangesAndCheck(fixture, `init bar`); + StringMapWrapper.set( + fixture.debugElement.componentInstance.objExpr, 'foo', false); + detectChangesAndCheck(fixture, `init bar`); - fixture.debugElement.componentInstance.objExpr = null; - detectChangesAndCheck(fixture, `init foo`); + fixture.debugElement.componentInstance.objExpr = null; + detectChangesAndCheck(fixture, `init foo`); - async.done(); - }); - })); + async.done(); + }); + })); it('should co-operate with the class attribute and class.name binding', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - var template = - '
'; + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + var template = + '
'; - tcb.overrideTemplate(TestComponent, template) - .createAsync(TestComponent) - .then((fixture) => { - detectChangesAndCheck(fixture, 'init foo baz'); + tcb.overrideTemplate(TestComponent, template) + .createAsync(TestComponent) + .then((fixture) => { + detectChangesAndCheck(fixture, 'init foo baz'); - StringMapWrapper.set(fixture.debugElement.componentInstance.objExpr, 'bar', true); - detectChangesAndCheck(fixture, 'init foo baz bar'); + StringMapWrapper.set( + fixture.debugElement.componentInstance.objExpr, 'bar', true); + detectChangesAndCheck(fixture, 'init foo baz bar'); - StringMapWrapper.set(fixture.debugElement.componentInstance.objExpr, 'foo', false); - detectChangesAndCheck(fixture, 'init baz bar'); + StringMapWrapper.set( + fixture.debugElement.componentInstance.objExpr, 'foo', false); + detectChangesAndCheck(fixture, 'init baz bar'); - fixture.debugElement.componentInstance.condition = false; - detectChangesAndCheck(fixture, 'init bar'); + fixture.debugElement.componentInstance.condition = false; + detectChangesAndCheck(fixture, 'init bar'); - async.done(); - }); - })); + async.done(); + }); + })); it('should co-operate with initial class and class attribute binding when binding changes', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - var template = '
'; + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + var template = '
'; - tcb.overrideTemplate(TestComponent, template) - .createAsync(TestComponent) - .then((fixture) => { - detectChangesAndCheck(fixture, 'init foo'); + tcb.overrideTemplate(TestComponent, template) + .createAsync(TestComponent) + .then((fixture) => { + detectChangesAndCheck(fixture, 'init foo'); - StringMapWrapper.set(fixture.debugElement.componentInstance.objExpr, 'bar', true); - detectChangesAndCheck(fixture, 'init foo bar'); + StringMapWrapper.set( + fixture.debugElement.componentInstance.objExpr, 'bar', true); + detectChangesAndCheck(fixture, 'init foo bar'); - fixture.debugElement.componentInstance.strExpr = 'baz'; - detectChangesAndCheck(fixture, 'init bar baz foo'); + fixture.debugElement.componentInstance.strExpr = 'baz'; + detectChangesAndCheck(fixture, 'init bar baz foo'); - fixture.debugElement.componentInstance.objExpr = null; - detectChangesAndCheck(fixture, 'init baz'); + fixture.debugElement.componentInstance.objExpr = null; + detectChangesAndCheck(fixture, 'init baz'); - async.done(); - }); - })); + async.done(); + }); + })); }); }) diff --git a/modules/@angular/common/test/directives/ng_for_spec.ts b/modules/@angular/common/test/directives/ng_for_spec.ts index 11963e4028..6b064d5dae 100644 --- a/modules/@angular/common/test/directives/ng_for_spec.ts +++ b/modules/@angular/common/test/directives/ng_for_spec.ts @@ -1,13 +1,4 @@ -import { - beforeEach, - beforeEachProviders, - ddescribe, - describe, - iit, - inject, - it, - xit, -} from '@angular/core/testing/testing_internal'; +import {beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xit,} from '@angular/core/testing/testing_internal'; import {expect} from '@angular/platform-browser/testing'; import {AsyncTestCompleter} from '@angular/core/testing/testing_internal'; import {TestComponentBuilder, ComponentFixture} from '@angular/compiler/testing'; @@ -25,482 +16,535 @@ export function main() { '
{{item.toString()}};
'; it('should reflect initial elements', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - tcb.overrideTemplate(TestComponent, TEMPLATE) - .createAsync(TestComponent) - .then((fixture) => { - fixture.detectChanges(); - expect(fixture.debugElement.nativeElement).toHaveText('1;2;'); - async.done(); - }); - })); + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + tcb.overrideTemplate(TestComponent, TEMPLATE) + .createAsync(TestComponent) + .then((fixture) => { + fixture.detectChanges(); + expect(fixture.debugElement.nativeElement).toHaveText('1;2;'); + async.done(); + }); + })); it('should reflect added elements', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - tcb.overrideTemplate(TestComponent, TEMPLATE) - .createAsync(TestComponent) - .then((fixture) => { - fixture.detectChanges(); + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + tcb.overrideTemplate(TestComponent, TEMPLATE) + .createAsync(TestComponent) + .then((fixture) => { + fixture.detectChanges(); - (fixture.debugElement.componentInstance.items).push(3); - fixture.detectChanges(); + (fixture.debugElement.componentInstance.items).push(3); + fixture.detectChanges(); - expect(fixture.debugElement.nativeElement).toHaveText('1;2;3;'); - async.done(); - }); - })); + expect(fixture.debugElement.nativeElement).toHaveText('1;2;3;'); + async.done(); + }); + })); it('should reflect removed elements', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - tcb.overrideTemplate(TestComponent, TEMPLATE) - .createAsync(TestComponent) - .then((fixture) => { - fixture.detectChanges(); + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + tcb.overrideTemplate(TestComponent, TEMPLATE) + .createAsync(TestComponent) + .then((fixture) => { + fixture.detectChanges(); - ListWrapper.removeAt(fixture.debugElement.componentInstance.items, 1); - fixture.detectChanges(); + ListWrapper.removeAt(fixture.debugElement.componentInstance.items, 1); + fixture.detectChanges(); - expect(fixture.debugElement.nativeElement).toHaveText('1;'); - async.done(); - }); - })); + expect(fixture.debugElement.nativeElement).toHaveText('1;'); + async.done(); + }); + })); it('should reflect moved elements', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - tcb.overrideTemplate(TestComponent, TEMPLATE) - .createAsync(TestComponent) - .then((fixture) => { - fixture.detectChanges(); + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + tcb.overrideTemplate(TestComponent, TEMPLATE) + .createAsync(TestComponent) + .then((fixture) => { + fixture.detectChanges(); - ListWrapper.removeAt(fixture.debugElement.componentInstance.items, 0); - (fixture.debugElement.componentInstance.items).push(1); - fixture.detectChanges(); + ListWrapper.removeAt(fixture.debugElement.componentInstance.items, 0); + (fixture.debugElement.componentInstance.items).push(1); + fixture.detectChanges(); - expect(fixture.debugElement.nativeElement).toHaveText('2;1;'); - async.done(); - }); - })); + expect(fixture.debugElement.nativeElement).toHaveText('2;1;'); + async.done(); + }); + })); it('should reflect a mix of all changes (additions/removals/moves)', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - tcb.overrideTemplate(TestComponent, TEMPLATE) - .createAsync(TestComponent) - .then((fixture) => { - fixture.debugElement.componentInstance.items = [0, 1, 2, 3, 4, 5]; - fixture.detectChanges(); + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + tcb.overrideTemplate(TestComponent, TEMPLATE) + .createAsync(TestComponent) + .then((fixture) => { + fixture.debugElement.componentInstance.items = [0, 1, 2, 3, 4, 5]; + fixture.detectChanges(); - fixture.debugElement.componentInstance.items = [6, 2, 7, 0, 4, 8]; - fixture.detectChanges(); + fixture.debugElement.componentInstance.items = [6, 2, 7, 0, 4, 8]; + fixture.detectChanges(); - expect(fixture.debugElement.nativeElement).toHaveText('6;2;7;0;4;8;'); - async.done(); - }); - })); + expect(fixture.debugElement.nativeElement).toHaveText('6;2;7;0;4;8;'); + async.done(); + }); + })); it('should iterate over an array of objects', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - var template = '
  • {{item["name"]}};
'; + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + var template = + '
  • {{item["name"]}};
'; - tcb.overrideTemplate(TestComponent, template) - .createAsync(TestComponent) - .then((fixture) => { + tcb.overrideTemplate(TestComponent, template) + .createAsync(TestComponent) + .then((fixture) => { - // INIT - fixture.debugElement.componentInstance.items = - [{'name': 'misko'}, {'name': 'shyam'}]; - fixture.detectChanges(); - expect(fixture.debugElement.nativeElement).toHaveText('misko;shyam;'); + // INIT + fixture.debugElement.componentInstance.items = + [{'name': 'misko'}, {'name': 'shyam'}]; + fixture.detectChanges(); + expect(fixture.debugElement.nativeElement).toHaveText('misko;shyam;'); - // GROW - (fixture.debugElement.componentInstance.items).push({'name': 'adam'}); - fixture.detectChanges(); + // GROW + (fixture.debugElement.componentInstance.items).push({'name': 'adam'}); + fixture.detectChanges(); - expect(fixture.debugElement.nativeElement).toHaveText('misko;shyam;adam;'); + expect(fixture.debugElement.nativeElement).toHaveText('misko;shyam;adam;'); - // SHRINK - ListWrapper.removeAt(fixture.debugElement.componentInstance.items, 2); - ListWrapper.removeAt(fixture.debugElement.componentInstance.items, 0); - fixture.detectChanges(); + // SHRINK + ListWrapper.removeAt(fixture.debugElement.componentInstance.items, 2); + ListWrapper.removeAt(fixture.debugElement.componentInstance.items, 0); + fixture.detectChanges(); - expect(fixture.debugElement.nativeElement).toHaveText('shyam;'); - async.done(); - }); - })); + expect(fixture.debugElement.nativeElement).toHaveText('shyam;'); + async.done(); + }); + })); it('should gracefully handle nulls', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - var template = '
  • {{item}};
'; - tcb.overrideTemplate(TestComponent, template) - .createAsync(TestComponent) - .then((fixture) => { - fixture.detectChanges(); - expect(fixture.debugElement.nativeElement).toHaveText(''); - async.done(); - }); - })); + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + var template = '
  • {{item}};
'; + tcb.overrideTemplate(TestComponent, template) + .createAsync(TestComponent) + .then((fixture) => { + fixture.detectChanges(); + expect(fixture.debugElement.nativeElement).toHaveText(''); + async.done(); + }); + })); it('should gracefully handle ref changing to null and back', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - tcb.overrideTemplate(TestComponent, TEMPLATE) - .createAsync(TestComponent) - .then((fixture) => { - fixture.detectChanges(); - expect(fixture.debugElement.nativeElement).toHaveText('1;2;'); + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + tcb.overrideTemplate(TestComponent, TEMPLATE) + .createAsync(TestComponent) + .then((fixture) => { + fixture.detectChanges(); + expect(fixture.debugElement.nativeElement).toHaveText('1;2;'); - fixture.debugElement.componentInstance.items = null; - fixture.detectChanges(); - expect(fixture.debugElement.nativeElement).toHaveText(''); + fixture.debugElement.componentInstance.items = null; + fixture.detectChanges(); + expect(fixture.debugElement.nativeElement).toHaveText(''); - fixture.debugElement.componentInstance.items = [1, 2, 3]; - fixture.detectChanges(); - expect(fixture.debugElement.nativeElement).toHaveText('1;2;3;'); - async.done(); - }); - })); + fixture.debugElement.componentInstance.items = [1, 2, 3]; + fixture.detectChanges(); + expect(fixture.debugElement.nativeElement).toHaveText('1;2;3;'); + async.done(); + }); + })); if (!IS_DART) { it('should throw on non-iterable ref and suggest using an array', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - tcb.overrideTemplate(TestComponent, TEMPLATE) - .createAsync(TestComponent) - .then((fixture) => { - fixture.debugElement.componentInstance.items = 'whaaa'; - try { - fixture.detectChanges() - } catch (e) { - expect(e.message).toContain( - `Cannot find a differ supporting object 'whaaa' of type 'string'. NgFor only supports binding to Iterables such as Arrays.`); - async.done(); - } - }); - })); + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + tcb.overrideTemplate(TestComponent, TEMPLATE) + .createAsync(TestComponent) + .then((fixture) => { + fixture.debugElement.componentInstance.items = 'whaaa'; + try { + fixture.detectChanges() + } catch (e) { + expect(e.message).toContain( + `Cannot find a differ supporting object 'whaaa' of type 'string'. NgFor only supports binding to Iterables such as Arrays.`); + async.done(); + } + }); + })); } it('should throw on ref changing to string', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - tcb.overrideTemplate(TestComponent, TEMPLATE) - .createAsync(TestComponent) - .then((fixture) => { - fixture.detectChanges(); - expect(fixture.debugElement.nativeElement).toHaveText('1;2;'); + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + tcb.overrideTemplate(TestComponent, TEMPLATE) + .createAsync(TestComponent) + .then((fixture) => { + fixture.detectChanges(); + expect(fixture.debugElement.nativeElement).toHaveText('1;2;'); - fixture.debugElement.componentInstance.items = 'whaaa'; - expect(() => fixture.detectChanges()).toThrowError(); - async.done(); - }); - })); + fixture.debugElement.componentInstance.items = 'whaaa'; + expect(() => fixture.detectChanges()).toThrowError(); + async.done(); + }); + })); it('should works with duplicates', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - tcb.overrideTemplate(TestComponent, TEMPLATE) - .createAsync(TestComponent) - .then((fixture) => { - var a = new Foo(); - fixture.debugElement.componentInstance.items = [a, a]; - fixture.detectChanges(); - expect(fixture.debugElement.nativeElement).toHaveText('foo;foo;'); - async.done(); - }); - })); + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + tcb.overrideTemplate(TestComponent, TEMPLATE) + .createAsync(TestComponent) + .then((fixture) => { + var a = new Foo(); + fixture.debugElement.componentInstance.items = [a, a]; + fixture.detectChanges(); + expect(fixture.debugElement.nativeElement).toHaveText('foo;foo;'); + async.done(); + }); + })); it('should repeat over nested arrays', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - var template = '
' + - '
' + - '
' + - '{{subitem}}-{{item.length}};' + - '
|' + - '
' + - '
'; + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + var template = '
' + + '
' + + '
' + + '{{subitem}}-{{item.length}};' + + '
|' + + '
' + + '
'; - tcb.overrideTemplate(TestComponent, template) - .createAsync(TestComponent) - .then((fixture) => { - fixture.debugElement.componentInstance.items = [['a', 'b'], ['c']]; - fixture.detectChanges(); - fixture.detectChanges(); - fixture.detectChanges(); - expect(fixture.debugElement.nativeElement).toHaveText('a-2;b-2;|c-1;|'); + tcb.overrideTemplate(TestComponent, template) + .createAsync(TestComponent) + .then((fixture) => { + fixture.debugElement.componentInstance.items = [['a', 'b'], ['c']]; + fixture.detectChanges(); + fixture.detectChanges(); + fixture.detectChanges(); + expect(fixture.debugElement.nativeElement).toHaveText('a-2;b-2;|c-1;|'); - fixture.debugElement.componentInstance.items = [['e'], ['f', 'g']]; - fixture.detectChanges(); - expect(fixture.debugElement.nativeElement).toHaveText('e-1;|f-2;g-2;|'); + fixture.debugElement.componentInstance.items = [['e'], ['f', 'g']]; + fixture.detectChanges(); + expect(fixture.debugElement.nativeElement).toHaveText('e-1;|f-2;g-2;|'); - async.done(); - }); - })); + async.done(); + }); + })); it('should repeat over nested arrays with no intermediate element', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - var template = '
'; + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + var template = '
'; - tcb.overrideTemplate(TestComponent, template) - .createAsync(TestComponent) - .then((fixture) => { - fixture.debugElement.componentInstance.items = [['a', 'b'], ['c']]; - fixture.detectChanges(); - expect(fixture.debugElement.nativeElement).toHaveText('a-2;b-2;c-1;'); + tcb.overrideTemplate(TestComponent, template) + .createAsync(TestComponent) + .then((fixture) => { + fixture.debugElement.componentInstance.items = [['a', 'b'], ['c']]; + fixture.detectChanges(); + expect(fixture.debugElement.nativeElement).toHaveText('a-2;b-2;c-1;'); - fixture.debugElement.componentInstance.items = [['e'], ['f', 'g']]; - fixture.detectChanges(); - expect(fixture.debugElement.nativeElement).toHaveText('e-1;f-2;g-2;'); - async.done(); - }); - })); + fixture.debugElement.componentInstance.items = [['e'], ['f', 'g']]; + fixture.detectChanges(); + expect(fixture.debugElement.nativeElement).toHaveText('e-1;f-2;g-2;'); + async.done(); + }); + })); it('should repeat over nested ngIf that are the last node in the ngFor temlate', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - var template = - `
`; + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + var template = + `
`; - tcb.overrideTemplate(TestComponent, template) - .createAsync(TestComponent) - .then((fixture) => { - var el = fixture.debugElement.nativeElement; - var items = [1]; - fixture.debugElement.componentInstance.items = items; - fixture.detectChanges(); - expect(el).toHaveText('0|even|'); + tcb.overrideTemplate(TestComponent, template) + .createAsync(TestComponent) + .then((fixture) => { + var el = fixture.debugElement.nativeElement; + var items = [1]; + fixture.debugElement.componentInstance.items = items; + fixture.detectChanges(); + expect(el).toHaveText('0|even|'); - items.push(1); - fixture.detectChanges(); - expect(el).toHaveText('0|even|1|'); + items.push(1); + fixture.detectChanges(); + expect(el).toHaveText('0|even|1|'); - items.push(1); - fixture.detectChanges(); - expect(el).toHaveText('0|even|1|2|even|'); + items.push(1); + fixture.detectChanges(); + expect(el).toHaveText('0|even|1|2|even|'); - async.done(); - }); - })); + async.done(); + }); + })); it('should display indices correctly', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - var template = - '
{{i.toString()}}
'; + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + var template = + '
{{i.toString()}}
'; - tcb.overrideTemplate(TestComponent, template) - .createAsync(TestComponent) - .then((fixture) => { - fixture.debugElement.componentInstance.items = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; - fixture.detectChanges(); - expect(fixture.debugElement.nativeElement).toHaveText('0123456789'); + tcb.overrideTemplate(TestComponent, template) + .createAsync(TestComponent) + .then((fixture) => { + fixture.debugElement.componentInstance.items = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; + fixture.detectChanges(); + expect(fixture.debugElement.nativeElement).toHaveText('0123456789'); - fixture.debugElement.componentInstance.items = [1, 2, 6, 7, 4, 3, 5, 8, 9, 0]; - fixture.detectChanges(); - expect(fixture.debugElement.nativeElement).toHaveText('0123456789'); - async.done(); - }); - })); + fixture.debugElement.componentInstance.items = [1, 2, 6, 7, 4, 3, 5, 8, 9, 0]; + fixture.detectChanges(); + expect(fixture.debugElement.nativeElement).toHaveText('0123456789'); + async.done(); + }); + })); it('should display first item correctly', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - var template = - '
{{isFirst.toString()}}
'; + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + var template = + '
{{isFirst.toString()}}
'; - tcb.overrideTemplate(TestComponent, template) - .createAsync(TestComponent) - .then((fixture) => { - fixture.debugElement.componentInstance.items = [0, 1, 2]; - fixture.detectChanges(); - expect(fixture.debugElement.nativeElement).toHaveText('truefalsefalse'); + tcb.overrideTemplate(TestComponent, template) + .createAsync(TestComponent) + .then((fixture) => { + fixture.debugElement.componentInstance.items = [0, 1, 2]; + fixture.detectChanges(); + expect(fixture.debugElement.nativeElement).toHaveText('truefalsefalse'); - fixture.debugElement.componentInstance.items = [2, 1]; - fixture.detectChanges(); - expect(fixture.debugElement.nativeElement).toHaveText('truefalse'); - async.done(); - }); - })); + fixture.debugElement.componentInstance.items = [2, 1]; + fixture.detectChanges(); + expect(fixture.debugElement.nativeElement).toHaveText('truefalse'); + async.done(); + }); + })); it('should display last item correctly', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - var template = - '
{{isLast.toString()}}
'; + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + var template = + '
{{isLast.toString()}}
'; - tcb.overrideTemplate(TestComponent, template) - .createAsync(TestComponent) - .then((fixture) => { - fixture.debugElement.componentInstance.items = [0, 1, 2]; - fixture.detectChanges(); - expect(fixture.debugElement.nativeElement).toHaveText('falsefalsetrue'); + tcb.overrideTemplate(TestComponent, template) + .createAsync(TestComponent) + .then((fixture) => { + fixture.debugElement.componentInstance.items = [0, 1, 2]; + fixture.detectChanges(); + expect(fixture.debugElement.nativeElement).toHaveText('falsefalsetrue'); - fixture.debugElement.componentInstance.items = [2, 1]; - fixture.detectChanges(); - expect(fixture.debugElement.nativeElement).toHaveText('falsetrue'); - async.done(); - }); - })); + fixture.debugElement.componentInstance.items = [2, 1]; + fixture.detectChanges(); + expect(fixture.debugElement.nativeElement).toHaveText('falsetrue'); + async.done(); + }); + })); it('should display even items correctly', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - var template = - '
{{isEven.toString()}}
'; + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + var template = + '
{{isEven.toString()}}
'; - tcb.overrideTemplate(TestComponent, template) - .createAsync(TestComponent) - .then((fixture) => { - fixture.debugElement.componentInstance.items = [0, 1, 2]; - fixture.detectChanges(); - expect(fixture.debugElement.nativeElement).toHaveText('truefalsetrue'); + tcb.overrideTemplate(TestComponent, template) + .createAsync(TestComponent) + .then((fixture) => { + fixture.debugElement.componentInstance.items = [0, 1, 2]; + fixture.detectChanges(); + expect(fixture.debugElement.nativeElement).toHaveText('truefalsetrue'); - fixture.debugElement.componentInstance.items = [2, 1]; - fixture.detectChanges(); - expect(fixture.debugElement.nativeElement).toHaveText('truefalse'); - async.done(); - }); - })); + fixture.debugElement.componentInstance.items = [2, 1]; + fixture.detectChanges(); + expect(fixture.debugElement.nativeElement).toHaveText('truefalse'); + async.done(); + }); + })); it('should display odd items correctly', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - var template = - '
{{isOdd.toString()}}
'; + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + var template = + '
{{isOdd.toString()}}
'; - tcb.overrideTemplate(TestComponent, template) - .createAsync(TestComponent) - .then((fixture) => { - fixture.debugElement.componentInstance.items = [0, 1, 2, 3]; - fixture.detectChanges(); - expect(fixture.debugElement.nativeElement).toHaveText('falsetruefalsetrue'); + tcb.overrideTemplate(TestComponent, template) + .createAsync(TestComponent) + .then((fixture) => { + fixture.debugElement.componentInstance.items = [0, 1, 2, 3]; + fixture.detectChanges(); + expect(fixture.debugElement.nativeElement).toHaveText('falsetruefalsetrue'); - fixture.debugElement.componentInstance.items = [2, 1]; - fixture.detectChanges(); - expect(fixture.debugElement.nativeElement).toHaveText('falsetrue'); - async.done(); - }); - })); + fixture.debugElement.componentInstance.items = [2, 1]; + fixture.detectChanges(); + expect(fixture.debugElement.nativeElement).toHaveText('falsetrue'); + async.done(); + }); + })); it('should allow to use a custom template', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - tcb.overrideTemplate( - TestComponent, - '
') - .overrideTemplate( - ComponentUsingTestComponent, - '
  • {{i}}: {{item}};
  • ') - .createAsync(ComponentUsingTestComponent) - .then((fixture) => { - var testComponent = fixture.debugElement.children[0]; - testComponent.componentInstance.items = ['a', 'b', 'c']; - fixture.detectChanges(); - expect(testComponent.nativeElement).toHaveText('0: a;1: b;2: c;'); + inject( + [TestComponentBuilder, AsyncTestCompleter], + (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { + tcb.overrideTemplate( + TestComponent, + '
    ') + .overrideTemplate( + ComponentUsingTestComponent, + '
  • {{i}}: {{item}};
  • ') + .createAsync(ComponentUsingTestComponent) + .then((fixture) => { + var testComponent = fixture.debugElement.children[0]; + testComponent.componentInstance.items = ['a', 'b', 'c']; + fixture.detectChanges(); + expect(testComponent.nativeElement).toHaveText('0: a;1: b;2: c;'); - async.done(); - }); - })); + async.done(); + }); + })); it('should use a default template if a custom one is null', - inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - tcb.overrideTemplate(TestComponent, `