I have a simple input with an ng-model to get the value of the input, here is my code :
angular
.module('thermofluor')
.directive('tm', tm)
tm.$inject = ['$timeout', '$q', '$rootScope', 'EVENTS'];
function tm($timeout, $q, $rootScope, EVENTS) {
var directive = {
link: link,
restrict: 'E',
templateUrl: 'tm.html',
scope: {
hideTm : '=',
canSaveTm: '='
}
};
return directive;
function link(scope, element) {
scope.calculateTm = calculateTm;
scope.deleteTm = deleteTm;
scope.saveTm = saveTm;
scope.comment = "";
/**
* Broadcast a EVENTS.CALCULATE_TM
*/
function calculateTm(){
console.log('Broadcast CALCULATE_TM ..');
$rootScope.$broadcast(EVENTS.CALCULATE_TM);
}
/**
* Broadcast a EVENTS.DELETE_TM
*/
function deleteTm(){
console.log('Broadcast DELETE_TM ..');
$rootScope.$broadcast(EVENTS.DELETE_TM);
}
/**
* Broadcast a EVENTS.SAVE_TM
*/
function saveTm(){
console.log('Broadcast SAVE_TM ..');
$rootScope.$broadcast(EVENTS.SAVE_TM, scope.comment);
}
}
}
And in the html template I have this :
<input ng-model="comment" class="form-control" type="text" id="tm-comment" name="tm-comment" placeholder="Comment"/>
<p>{{ comment }}</p>
The ng-model seems works fine, when I change the text in the input the paragraph under change too, but when I click on the button who throw the saveTm() function, in the function my values is the default one (""), and for example if the default was "test" the value in the function will be "test", even if I change it in the input.
Why ?
linkfunction part of some directive or something similar? if it is, please post all of the code so we can see at least howscopeis passed.scope: { hideTm : '=', canSaveTm: '=', comment: '=' }