0
我有一個倒計時,偉大的作品。但即時通訊尋找添加更多的功能。àngularjs指令倒計時
在這種情況下,我想輸入一個字符串用於倒計時(結果將是STRING +倒計時)。
該字符串是在初始混亂,但我不能完全得到爲什麼我不能在指令中檢索它。
<countdown init-val="vm.timersteal " init-mess="Du kan utføre enkel krim igjen om" class="ng-isolate-scope"></countdown>
init-val工作,但不是init-mess。我怎樣才能得到倒計時控制器功能內的初始混亂?
angular
.module('users')
.directive('countdown', countdown);
function getFormattedTime(secs) {
var date = new Date(null);
date.setSeconds(secs);
return date.toISOString().substr(11, 8);
}
function countdown() {
return {
restrict: 'E',
template: '<div class=\"{{class}}\" style=\"float:left; margin-right:5px;\"">{{result}}</div>',
scope: {
initVal: '=',
initmess: '='
},
controller: function($scope, $interval) {
console.log($scope.initVal);
console.log($scope.initmess);
$scope.countdownVal = $scope.initVal;
$scope.countdownVal = Math.floor($scope.countdownVal/1000) - Math.floor(Date.now()/1000);
var b = getFormattedTime($scope.countdownVal);
$scope.class = "";
if ($scope.countdownVal > 0) {
$scope.result = b;
} else {
$scope.class = "blink";
$scope.result = "00:00:00";
}
$interval(function() {
if ($scope.countdownVal > 0) {
$scope.class = "";
$scope.countdownVal = $scope.initVal;
$scope.countdownVal = ($scope.initVal/1000) - Math.floor(Date.now()/1000);
$scope.result = getFormattedTime($scope.countdownVal);
} else {
$scope.class = "blink";
$scope.result = "00:00:00";
}
}, 1000);
}
}
};
UPDATE:
現在我得到:
angular.js:13920 Error: [$parse:lexerr] Lexer Error: Unexpected next character at columns 10-10 [ø] in expression [Du kan utføre enkel krim igjen om].
這可怎麼修復,允許一個字符串?
我猜 'M' 應該是資本的情況下, 'initmess' 變量... –
的'initmess'在首都應該有'm'。 'initMess' – z0mBi3
thanks @ Mr.Noddy更新了答案。 – maria