I am facing an issue with my model that I want to make editable, but for some reason nothing changes - the textbox fails to appear and the model remains unchanged when using ng-view
.
I can confirm that the function enableEditor()
is being triggered as I see it in the console log.
If I include the code inline in the index.html without the profile.html, everything works perfectly fine.
Below are the relevant files:
app.js
var proGamersApp = angular.module('proGamersApp', ['ngResource']).
config(function ($routeProvider) {
$routeProvider.
when('/', { controller: 'ProfileController', templateUrl: '/app/partials/profile.html' }).
otherwise({ redirectTo: '/' });
});
var ProfileController = function ($scope) {
$scope.init = function () {
$scope.title = 'first title';
};
$scope.init();
$scope.enableEditor = function () {
console.log('enableEditor()')
$scope.editorEnabled = true;
$scope.editableTitle = 'second title';
$scope.title = 'second title';
};
...
};
index.html
<!doctype html>
<html ng-app="proGamersApp">
<head>
<title>Pro Gamers</title>
<!-- Scripts -->
<script src="/app/lib/angular.min.js"></script>
<script src="/app/lib/angular-resource.js"></script>
<script src="/app/app.js"></script>
</head>
<body>
<div ng-view></div>
</body>
</html>
profile.html
<div ng-hide="editorEnabled">
{{title}}
<a href="#" ng-click="enableEditor()">Edit title</a>
</div>
<div ng-show="editorEnabled">
<input ng-model="title" ng-show="editorEnabled">
<a href="#" ng-click="save()">Save</a>
or
<a href="#" ng-click="disableEditor()">cancel</a>.
</div>
Can anyone help me identify what I might be doing wrong?
Thank you