我用$ digest做错了什么。怎么写正确的方法? 我知道$ digest会更新页面上的结果。但是以什么方式接受权利?
(function() {
'use strict';
function ngCell($compile) {
var template = '<div class="board__cell-wrapper__cell__bubble" ng-if="cell.name == \'blank\'"></div><p>{{cell.name}}</p>';
function compileStartPositionTemplate (element, scope) {
element.html(template);
}
return {
scope: true,
restrict: 'A',
template: template,
link: function ($scope, element, attrs, controller) {
element.on('click', function(event) {
//
});
$scope.$on('newGame', function () {
var el = element.html(template);
$compile(el.contents())($scope);
$scope.$digest();
});
}
};
}
ngCell.$inject = ['$compile'];
angular.module('app').directive('ngCell', ngCell);
}());