HTML:
<body ng-app="EditApp">
<div ng-controller="MainController">
<h1 click-to-edit>This is something I want to edit</h1>
</div>
</body>
Javascript:
angular.module("EditApp", [])
.controller("MainController", ['$scope', function($scope){
$scope.text = "This is something I would like to edit";
}])
.directive("clickToEdit", function(){
return {
restrict: 'EA',
template: " <input type='text' value='{{ text }}' ng-show='showInput'/> <div ng-transclude ng-hide='showInput'></div>",
transclude: true,
link: function (scope, element, attrs) {
scope.showInput = false
element.on("click", function(){
scope.$parent.showInput = true
})
}
}
})
Why is the showInput not changing? Or is it but I have to do a scope.$apply() ? Should I be passing in the scope somehow within the on click function?
Thanks!