1

I´m quite new to angular2 and i have a question. I´m writing an app to manage a TV-Server. In the app i have different components, all of them have a view!

Now I want to have a component 'newTimerComponent', which is a own component, but a 'child' of the other components. This component is "just" a modal.

My aim: If i click on a button in any of the other components, the 'newTimerComponent' opens the modal and i can do something in the modal. Moreover, i need to share some data between the components and the 'newTimerComponent', but it´s just one variable and a return value from the 'newTimerComponent'.

Here´s my code from the 'NewTimerComponent' so far:

@Component({
    selector: 'timer',
    moduleId: module.id,
    templateUrl: 'timer.component.html'
})


export class TimerComponent implements OnInit {

    private selectedTimer;
    private newTimer: boolean;

    constructor(private router: Router, private variables: Variables, private apiService: ApiService, private formatter: Formatter, private helperService: HelperService) {
        if (!this.variables.getIsLoggedIn()) {
            this.router.navigate(['login']);
        }
    }

    ngOnInit() {

    }

}

The HTML of this comonent:

    <div class="modal fade" id="myModal" tabindex="-1" role="dialog"
        aria-labelledby="myModalLabel" *ngIf="selectedTimer">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"
                        aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                    <h3 class="modal-title" *ngIf="newTimer">Header</h3>
                </div>
                <div class="modal-body">
// deleted everything else
            </div>
        </div>
    </div>

What do i have to do, so that i can use this component in any other components??

Thanks so much :)

Junias
  • 3,037
  • 2
  • 15
  • 21
  • Check: http://stackoverflow.com/questions/36566698/cant-initialize-dynamically-appended-html-component-in-angular-2 it might help on creating dynamic modals – eko Nov 25 '16 at 12:41
  • Thanks! I read it, but i hope everyone else has another suggestion, cause i "just" want to have a modal in an own component... This cant be so difficult :O – Junias Nov 25 '16 at 13:37

0 Answers0