简体   繁体   English

角度事件不会更新页面

[英]angular event doesn't update page

I'm converting a page in a mvc application with a lot of inline jquery javascript to angular using typescript. 我正在使用TypeScript将具有很多内联jquery javascript的mvc应用程序中的页面转换为angular。

The first calls works fine but I have a problem: based on a selection in a dropdown, the event updates several controls in the view, make a few ajax calls and finally update the view with the data from the calls. 第一次调用可以正常工作,但是我有一个问题:基于下拉菜单中的选择,该事件将更新视图中的多个控件,进行几次ajax调用,最后使用调用中的数据更新视图。

Seems the conversion is working fine, but at the end of the call the page isn't updated. 似乎转换工作正常,但在通话结束时页面未更新。

  1. I tried to remove all the old jquery code to avoid problems. 我试图删除所有旧的jquery代码,以避免出现问题。

  2. batarang and java console reports no errors. batarang和Java控制台未报告任何错误。

  3. the final ajax call is done and the result shown in a debug. 最后的ajax调用完成,结果显示在调试中。

All seems to work fine, but the page isn't updated. 一切似乎正常,但页面未更新。

How can I find the problem? 如何找到问题?

thanks 谢谢

Without seeing any code, it's difficult to answer but if you bind an event to an element and want to update something in the callback, you will have to use $apply 没有看到任何代码,很难回答,但是如果将事件绑定到元素并想更新回调中的某些内容,则必须使用$ apply

scope.$apply(function () {
    // your code
});

$apply will trigger a $digest cycle, and should be used when you want to update something while being outside angular's context. $ apply将触发一个$ digest循环,当您想在angular的上下文之外进行更新时应使用$ apply。

If you want to "find the problem" then you can use the following option. 如果要“查找问题”,则可以使用以下选项。

  1. Go to Internet Explorer (10 or 11) . 转到Internet Explorer(10或11)

  2. Select " Internet Options " from the settings menu. 从设置菜单中选择“ Internet选项 ”。

  3. Go to the " Advanced " tab (the last tab) 转到“ 高级 ”标签(最后一个标签)

  4. Settings are listed and select " Display a notification about every script error " 列出设置,然后选择显示有关每个脚本错误的通知

  5. Deselect the " Disable Script debugging (Internet Explorer) " and " Disable script debugging (Other) " 取消选择禁用脚本调试(Internet Explorer) ”和“ 禁用脚本调试(其他)

  6. Run the program again, you will get notification about the real issue that happens while displaying actual result. 再次运行该程序,您将在显示实际结果时收到有关发生的实际问题的通知。

Most likely you are not handling your asynchronous calls correctly. 您很可能没有正确处理异步调用。 It's impossible to tell from your question but it is a very common mistake with symptoms as you describe. 从您的问题中无法分辨出来,但这是您所描述的症状中非常常见的错误。

Make sure you are updating your model within the .then() method of a promise returned from an $http request. 确保在$http请求返回的promise的.then()方法中更新模型。 For example 例如

someFnDoingHttpRequest().then(function(data){ 
        // updated the model with the data 
        })

Also (another common mistake) make sure someFnDoingHttpRequest() returns a promise. 另外(另一个常见错误),请确保someFnDoingHttpRequest()返回一个someFnDoingHttpRequest()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM