Angularjs Angular在添加新项后不刷新表

Angularjs Angular在添加新项后不刷新表,angularjs,Angularjs,当我得到所有;角度函数来刷新它调用的表,因为我收到了警报消息,但它不刷新表 我是AngularJS的新手,我不知道如何解决这个问题 请帮帮我 这是我的密码: [HttpGet] public JsonResult GetAllContinents() { MyDatabaseEntities db = new MyDatabaseEntities(); var Result = (from con

当我得到所有;角度函数来刷新它调用的表,因为我收到了警报消息,但它不刷新表

我是AngularJS的新手,我不知道如何解决这个问题

请帮帮我

这是我的密码:

        [HttpGet]
        public JsonResult GetAllContinents()
        {

            MyDatabaseEntities db = new MyDatabaseEntities();
            var Result = (from con in db.Continents select new { ContinentId = con.ContinentId, ContinentName = con.ContinentName.Trim() }).ToList();
            return Json(Result, JsonRequestBehavior.AllowGet);

        }


HTML:




<div data-ng-controller="myCntrl">


    <div class="col-md-12">
        <table class="table table-bordered table-hover" style="width:800px">
            <thead>
                <tr>
                    <th><b></b>ID<b></b></th>
                    <th>continent Name</th>
                    <th>Modify</th>

                </tr>
            </thead>
            <tbody>

                <tr data-ng-repeat="con in ContinentsList">
                    <td>{{con.ContinentId}}</td>
                    <td>{{con.ContinentName}}</td>
                    <td>
                        <button class="btn btn-md glyphicon glyphicon-trash"
                                title="Click here to delete record" />
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</div>


    <div data-ng-controller="myCntrl">
    Enter Continent Name:  <input type="text" ng-model="Continent.ContinentName" />
    <input type="button" value="Add" ng-click="AddContinent()" />
</div>


AngularJs:


app.controller("myCntrl", function ($scope, $http,  angularService) {



    $scope.GetAll = function () {

        $scope.ContinentsList = [];
        $http.get('/Home/GetAllContinents')
           .success(function (data) {


               $scope.ContinentsList = data;
               alert('Done!')

           })
           .error(function (msg) {
               alert(msg);
           })

    };


 $scope.GetAll();

 $scope.AddContinent = function () {
     $http.post('/Home/AddContinent', { Con: $scope.Continent })
     .success(function (data) {
         $scope.clear();
         $scope.GetAll();

     })
     .error(function (msg) {
         alert(msg)
     })


 };`enter code here`

提前感谢您

您必须在功能范围之外定义该功能

       $scope.ContinentsList = [];
        function getAll () {

    $http.get('/Home/GetAllContinents')
       .success(function (data) {
           $scope.ContinentsList = data;

           alert('Done!')

       })
       .error(function (msg) {
           alert(msg);
       })

};

从以下位置卸下ng控制器:

   <div data-ng-controller="myCntrl">
    Enter Continent Name:  <input type="text" ng-model="Continent.ContinentName" />
    <input type="button" value="Add" ng-click="AddContinent()" />
</div>
现在您有两个范围和两个内容列表,这就是问题所在。在一个范围中,您有一个在视图中显示的列表,在第二个范围中,您添加元素并尝试刷新列表

这是工作代码:

<div  data-ng-controller="myCntrl">


    <div class="col-md-12">
        <table class="table table-bordered table-hover" style="width:800px">
            <thead>
                <tr>
                    <th><b></b>ID<b></b></th>
                    <th>continent Name</th>
                    <th>Modify</th>

                </tr>
            </thead>
            <tbody>

                <tr data-ng-repeat="con in ContinentsList">
                    <td>{{con.ContinentId}}</td>
                    <td>{{con.ContinentName}}</td>
                    <td>
                        <button class="btn btn-md glyphicon glyphicon-trash"
                                title="Click here to delete record" />
                    </td>
                </tr>
            </tbody>
        </table>
    </div>

    Enter Continent Name:  <input type="text" ng-model="Continent.ContinentName" />
    <input type="button" value="Add" ng-click="AddContinent()" />
</div>

我移除了它,它终于开始工作了!!非常感谢…我是angular方面的新手,所以你能告诉我避免再次出现这种情况的错误吗?阅读本文-这对angular开发人员非常重要