Please check this codepen, when clicked on the button click me to reset name, the name input should be reset to empty, when I do console.log on the directive scope, I do see name is set to empty string, but the value in the view not get updated. What's wrong?
angular.module('mainApp', [])
.directive('myTab', function() {
return {
restrict: 'E',
template: 'name: <input type="text" ng-model="name">',
controller: function($location, $scope) {
$scope.name = 'myname';
$('#clickMeToReset').on('click', function() {
$scope.name = '';
})
}
};
})
.directive('myMenu', function() {
return {
restrict: 'E',
template: '<button id="clickMeToReset">click me to reset name</button>'
};
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="mainApp">
<my-menu></my-menu>
<my-tab></my-tab>
</div>