I'm working on a project in Rails that also uses AngularJS. First of all, I have a variable called @resource that contains an end time
<input style="display:none" ng-model="remainingTime" ng-init="remainingTime = <%= (resource.available_until.to_f - DateTime.now.to_f).to_i %>">
This obtains the remaining time for an X task and is displayed as follows (without display none).
That value obtained I must access it from the controller.
In the controller I have the following:
function UserEvaluationsNewCtrl ($log, $scope) {
console.log($scope.remainingTime)
}
When I want to access from the controller, the variable show "undefined" :/
Any help is useful. Thank you!!!
Edited:
remainingTime=-39698
-The negative number is correct-
Edited 2: Complete controller:
;(function () {
'use strict';
// Define controller
function UserEvaluationsNewCtrl ($log, $scope) {
$log.debug('UserEvaluationsNewCtrl: Hi')
var vm = this
vm.data = angular.extend({}, rails_data || {})
vm.evaluationData = vm.data.resource
vm.evaluationDataStringified = ''
$scope.$watch(function(){
return vm.evaluationData
}, function(newValue, oldValue){
vm.evaluationDataStringified = angular.toJson(newValue)
$log.debug('ResourcesNewCtrl: $watch vm.evaluationDataStringified: to JSON output:', vm.evaluationDataStringified)
}, true)
console.log($scope)
}
// Inject dependencies
UserEvaluationsNewCtrl.$inject = ['$log', '$scope']
// Register controller
angular
.module('app.controllers.user_evaluations.new', [])
.controller('UserEvaluationsNewCtrl', UserEvaluationsNewCtrl)
})();


$scope?console.log(test)line toconsole.log($scope)and update the question with the output you getconsole.log($scope.formCtrl.remainingTime)