我是angularjs的新手。我有一个显示倒计时的指令endDate
。使用硬编码值一切正常:
var endDate = new Date("2013-11-26T10:00:00Z");
但是我无法管理如何从控制器或渲染模板动态地将值传递给指令,因为我的指令有两个用例。
CountDownDirective.js:
app.directive("countdown", ["$window", function($window) {
return {
restrict: "EA",
replace: true,
link: function(scope, element, attrs, controller) {
function countdown(){
var endDate = new Date("2013-11-26T10:00:00Z"); //hardcode
//some logic...
}
countdown();
}
}
}]);
SomeController.js:
app.controller("SomeController", ["$scope", '$rootScope', "APIService",
function($scope, $rootScope, APIService){
APIService.get('end_data').then(function(response){
$scope.end_data = response;
// response is "2013-11-26T10:00:00Z"
});
//some logic...
}
]);
模板_one.html:
<div ng-controller="SomeController">
<div countdown>...</div>
</div>
模板_两个.html:
<div countdown end-date="2013-11-26T10:00:00Z">...</div>
提前感谢您的帮助。