首页 \ 问答 \ 清空Angular中的输入字段(Emptying input field in Angular)

清空Angular中的输入字段(Emptying input field in Angular)

当用户输入并且然后清除输入字段中的文本时,角度似乎具有不同的行为,具体取决于是否需要此字段。

看看这个例子 。 默认情况下,模型是user = {"name":"guest","last":"visitor"} 。 清除这两个字段时,模型变为user = {"last":""}而我会预期user = {}

为什么会这样? 而且,有没有办法让两个领域的相同行为都没有使他们都(不)是必需的?

更新:

我最后使用了手表的解决方法:

$scope.$watch('user',function(newValue) {
  for (var prop in newValue) {
    if (newValue.hasOwnProperty(prop)){
      if (newValue[prop] !== undefined && newValue[prop] == "")
        newValue[prop] = undefined;
    }
  }
}, true);

最有可能的是,最后一个if条件可以更有效地写,但至少它似乎按预期工作。


Angular seems to have a different behavior when a user enters and then clears text in an input field depending if this field is required or not.

Take a look at this example. By default the model is user = {"name":"guest","last":"visitor"}. When clearing both fields the model becomes user = {"last":""} whereas I would have expected user = {}.

Why is this the case? And, is there a way to get the same behavior for both fields without making them both (not) required?

Update:

I used a workaround with watch in the end:

$scope.$watch('user',function(newValue) {
  for (var prop in newValue) {
    if (newValue.hasOwnProperty(prop)){
      if (newValue[prop] !== undefined && newValue[prop] == "")
        newValue[prop] = undefined;
    }
  }
}, true);

Most likely the last if-condition could be written more efficiently, but at least it seems to work as expected.


原文:https://stackoverflow.com/questions/33274220
更新时间:2022-11-08 10:11

最满意答案

您遇到问题的网址在我的共享对话框预览以及Facebook上的最后一篇文章中看起来很不错。 所以可能只是一个缓存问题。

至于你的第一个问题,刮板访问你的网站的频率 - 请参阅https://developers.facebook.com/docs/sharing/opengraph/using-objects#update

已经存在的帖子不会自动更新,但您作为帖子所有者可以请求FB更新内容。 您需要进入单个帖子视图(所以从您的供稿/时间线,点击帖子顶部的日期链接),有一个名为“刷新共享附件”的选项。


The URL you had a problem with looked fine for me, in share dialog preview as well as in the final post on Facebook. So likely just a caching issue.

As for your first question, how often the scraper visits your site – see https://developers.facebook.com/docs/sharing/opengraph/using-objects#update

Already existing posts will not automatically be updated, but you as the post owner can request FB to update the content. You need to go into the single post view (so from your feed/timeline, click the date link on top of the post), there is an option called “Refresh share attachment”.

相关问答

更多
  • 编辑 Facebook一直表现出一些热爱,现在正在让任何人都拥有IP块 https://developers.facebook.com/docs/sharing/best-practices#crawl Facebook刮刀 许多平台服务(如Social Plugins和Open Graph)都要求我们的系统能够访问您的网页。 我们认识到在某些情况下,您可能不想在公共互联网上,测试期间或出于其他安全原因使用这些页面。 为了促进这一点,您应该在您的安全系统中例外,以允许Facebook通过添加以下IP范围来缩 ...
  • 他们刚在他们的博客上公布了这一消息。 要获得它们,请使用user_questions或friends_questions权限向USER_ID / questions端点发出HTTP GET请求。 更新:他们还刚刚宣布 ,您现在可以通过API创建问题。 They just announced this is available on their blog. To get them, issue an HTTP GET request to the USER_ID/questions endpoint with ...
  • 那是我了:) 也许你没有得到的是Python中classmethod的含义。 在您的情况下,它是属于您的SQLlitePipeline类的方法。 因此, cls是SQLlitePipeline类本身。 Scrapy调用此管道方法传递crawler对象,Scrapy自行实例化。 到目前为止, 我们还没有SQLlitePipeline实例 。 换句话说,管道流程尚未开始。 从爬虫的设置中获取所需的参数( table )后, from_crawler最终通过执行cls(table)返回管道的实例 (记住cls是什 ...
  • 看看使用Typhoeus和Hydra 。 他们可以很容易地并行处理URL。 除非您必须从每个页面请求特殊数据,否则不需要使用机械化。 对于一个普通的爬虫,你可以使用Open :: URI和Nokogiri来获取主体并解析它,而不需要Mechanize的开销或者额外的功能。 为了您的目的,用Typhoeus代替Open :: URI并让Hydra处理线程管理。 请记住,如果您尝试一次完成所有操作,抓取200k个网站将会使您的带宽饱和。 这会让你的Rails站点不可用,所以你需要限制你的请求。 而且,这意味着你 ...
  • npm网站存在问题,但响应不佳。 第二天同样的命令工作。 There was a issue with npm website and it was not responding well. Same command worked next day.
  • 您遇到问题的网址在我的共享对话框预览以及Facebook上的最后一篇文章中看起来很不错。 所以可能只是一个缓存问题。 至于你的第一个问题,刮板访问你的网站的频率 - 请参阅https://developers.facebook.com/docs/sharing/opengraph/using-objects#update 已经存在的帖子不会自动更新,但您作为帖子所有者可以请求FB更新内容。 您需要进入单个帖子视图(所以从您的供稿/时间线,点击帖子顶部的日期链接),有一个名为“刷新共享附件”的选项。 The ...
  • 首先,我不认为需要递归调用。 它只会使你的代码更复杂。 您可以使用两种方法,一种方法来检查数据库中是否存在URL,并基于要插入或继续的逻辑。 另一种从页面获取数据的方法。 所以我会写这样的东西: public class htmlCrawler{ public static db_Connection db = new db_Connection(); public htmlCrawler(String url){ getLinksFromPage(url); } publi ...
  • 在Selenium 2 / Web Driver中使用HTML Unit进行无头浏览器“模拟”。 它工作正常。 所以我认为没有理由不尝试Html Unit。 您也可以查看Selenium 2 / Web Driver 。 HTML Unit is used in Selenium 2/Web Driver for headless browser "simulation". There it works fine. So I see no reason not to try Html Unit. May y ...
  • 目前尚不清楚您希望在Google+上抓取什么内容,但听起来您想要将Google+ API用于网络 。 特别是,您可能希望使用people.get , activities.search , activities.list和/或comments.list HTTP API说明。 但请注意,这只会返回未与社区共享的公众意见,即使该社区是公共社区也是如此。 It isn't clear exactly what you're looking to crawl on Google+, but it sounds l ...
  • 我解决了它创建我自己的中间件:RedirectCrawlers

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)