Is there any way that I can create a template in AngularJS but not run it until some event?
Actually I am using SignalR. So when server calls a client function then I want some HTML to show based on the data sent by server.
Suppose I am making a Chess Game. I don´t have the board to display on the page until the server sends it. In HandleBar I can create a template and when the server sends the board in json format I can compile the template and display it on page.
gameHub.client.buildBoard = function(game){
var template = Handlebars.compile($("board-template").html());
$("board").html(template(game.Board))
}
This builBoard function gets called by server.
In AngularJS I have to create a Controller, but the $scope.board has not loaded let.
The angular Code is
<div ng-app="game">
<div ng-controller="boardController">
<div ng-repeat="row in board.Pieces">
// Display Pieces
</div>
</div>
JS
var app = angular.module("game", []);
app.controller("boardController", function ($scope) {
$scope.size = 5;
$scope.board= [];
});
Here the board is initialized to empty array. Now the server will call the buildBoard() function with the necessary data required.
gameHub.client.buildBoard = function(board){
// Code to take this board object and assign it to the $scope.board
}
From here (outside the scope of controller ), how can I update the $scope.board array?