简体   繁体   English

JavaScript表单如何提交火灾angularjs事件?

[英]how can javascript form submit fire angularjs event?

I have a form submit by regular javascript outsite angular. 我有一个通过常规javascript外场角度提交的表单。 The form is successfuly submit and update the database. 表单成功提交并更新数据库。 I have a $http inside angularjs to query the data. 我在angularjs里面有一个$ http来查询数据。

My question is once submit the form, how can I refresh data inside angularjs? 我的问题是一旦提交表单,如何在angularjs中刷新数据?

sample javascript submit: 示例javascript提交:

$.getJSON('/Api/Cbs/setPost', inputPost, function(rsp){
  if(rsp.status > 0){alert('submited');
}

here is my code in angularjs 这是我在angularjs中的代码

$http.get('echo U('Api/Cbs/getPostList')')
.then(function(rsp){
  console.log('angular-getPost', rsp);
  $scope.postList = rsp.data;
});

the $http.get() fire only once on page load, not keep watching the API data update. $ http.get()仅在页面加载时触发一次,而不是一直关注API数据更新。

You can get scope by DOM search: 您可以通过DOM搜索获得范围:

angular.element(controllerId).scope().$apply("getHttp();");

Where controllerId - id attribute of you controller tag, eg: 其中controllerId-控制器标签的id属性,例如:

<div ng-controller="myController" id="controllerId">

And getHttp() method is declared on scope: 并在作用域上声明了getHttp()方法:

  $scope.getHttp = function () {
    $http.get('echo U('Api/Cbs/getPostList')')
    .then(function(rsp){
      console.log('angular-getPost', rsp);
      $scope.postList = rsp.data;
    });
  };

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

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