angular.js
私はコントローラーを書いていた今日から始めたばかりです:
myApp.controller('RepetitionController', ['$scope', '$location', 'repetitionService',
function ($scope, $location, repetitionService) {
$scope.questions = repetitionService.getQuestions();
$scope.questionsLeft = $scope.questions.length;
$scope.questionsAnswered = 0;
$scope.percentageLeft = ($scope.questionsLeft == 0 ? 100 : 0);
$scope.repetitonState = ???
$scope.endRepetition = function () {
repetitionService.clearSelectedSets();
$location.path("/setsAndCollections");
}
$scope.submitAnswer = function () {
alert("alert");
}
}]);
私は疑問に思い始めました。
三項演算子を使用して の初期状態を作成したことがわかります$scope
。今、私のrepetitionState
フィールドでは、このようなものが必要です(questionsLeft === 0 ? 'finished' : questions[0].type)
。
オブジェクトにデータを入力した後に呼び出される関数、$scope
ある種のポストコンストラクターを定義する方法はありますか?
または、関数を「監視」する方法があるので、次のように書くことができます
$scope.repetitionState = function(){
///logic here
};
私は書く必要がある状況があるのではないかと心配しています.logicalExpression ? anonymousFunction () : someOtherAnonymousFunction()
私にとって、これらすべての無名関数をネストすることは(今のところ)読みにくいangular
です.このような状況で。