以下代码不起作用:
<body ng-app="flapperNews" ng-controller="MainCtrl">
<form ng-submit="addPost()">
<input type="text" class="form-control" placeholder="Fill in a title" ng-model="title" />
<input type="text" class="form-control" placeholder="Fill in a link" ng-model="link" />
<button type="submit" ng-disabled="!title">Add a new post</button>
</form>
</body>
事实上,它有效,但它做得太多了。它在标题为空时禁用按钮,这是正确的,但它也将禁用第一个输入字段(在firefox中)。在safari中这很好用。
AngularJS模块:
/* global angular */
var app = angular.module('flapperNews', []);
app.controller('MainCtrl', ['$scope', function ($scope) {
$scope.posts = [
{title: "post 1", upvotes: 5},
{title: "post 2", upvotes: 7},
{title: "post 3", upvotes: 3},
{title: "post 4", upvotes: 2},
{title: "post 5", upvotes: 6}
];
$scope.addPost = function() {
$scope.posts.push({
title: $scope.title,
upvotes: 0,
link: $scope.link
});
$scope.title = "";
$scope.link = "";
};
}]);
有什么我想念的吗?如果是这样,为什么它会在除Firefox之外的所有浏览器中完美运行?
演示代码:http://embed.plnkr.co/rBQOC9RbroQM5E3bbLZy/preview
更新
该错误无法在Plunker和JSFiddle中复制。显然有一个缓存问题,Firefox中的强制刷新解决了这个问题。
答案 0 :(得分:0)
显然存在缓存问题,Firefox强制刷新解决了这个问题。