[英]AngularJs Model changes don't update
我有一個要編輯的模型,但是由於某種原因, 沒有任何變化,使用ng-view
時,文本框沒有顯示,並且模型也沒有更新 。
我可以看到使用console.log
調用功能enableEditor()
。
如果我在沒有profile.html的情況下以內聯而不是在index.html 中用 ng-view
編寫它,則一切運行正常。
這是文件:
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>
有人知道我在做什么錯嗎?
謝謝
鏈接添加到您的地址,導致路由器刷新頁面並破壞所有$ scope vars。 不要使用空白錨,而應使用樣式類似於錨的跨度:
span:hover {
cursor:pointer;
}
這只會使光標成為食指,並根據需要自定義顏色。 根據您的評論,不要將target=_self
添加到href中,請在以下位置添加:
<a href="#" target=_self ng-click="save()">Save</a> //prevent address bar change
就像我之前說的那樣,請改用spans。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.