Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 角度不显示我在模板html页面的控制器中设置的值_Javascript_Jquery_Angularjs_Ajax - Fatal编程技术网

Javascript 角度不显示我在模板html页面的控制器中设置的值

Javascript 角度不显示我在模板html页面的控制器中设置的值,javascript,jquery,angularjs,ajax,Javascript,Jquery,Angularjs,Ajax,我对angularjs相当陌生,我仍然在控制器中使用jQueryAjax调用。是的,我最终会转换,但这是我的问题: 我的成功: success: function (data) { var json = $.parseJSON(data); console.log(json); // This correctly loops over EACH record and spits out the total record count, thus the variable "js

我对angularjs相当陌生,我仍然在控制器中使用jQueryAjax调用。是的,我最终会转换,但这是我的问题:

我的成功:

success: function (data) {
    var json = $.parseJSON(data);
    console.log(json);  // This correctly loops over EACH record and spits out the total record count,  thus the variable "json" indeed is called multiple time and logging to chrome debugger just fine
            $scope.commentResult = json;  // TRYING to just set this variable each time this $.ajax function is called within the success section 
            //angular.element('#commentCount').text(json);  // my attempt to set a span id text to the variable holding the value
        },....
我认为设置这个范围值应该显示得很好

$scope.commentResult = json;
但它没有出现

HTML页面我调用一个函数并传递一个变化的值tip.id {{setCommentCount(tip.id)}

然后,我尝试从控制器设置它——上面的ajax调用

<span id="commentCount">Total Count: {{commentResult}}</span>
该函数调用正确地传入循环中不断变化的tip.id

然后我有$scope.detailFrame设置

 ng-src="{{detailFrame}}"
所以它适用于另一个元素ng src

显示更多的html和js代码


如果
commentResult
是json格式的,请在模板中执行以下操作

{{ commentResult | json }}
在成功函数中,自己创建一个摘要循环

$scope.$apply(function(){
    $scope.commentResult = json;
})
将var分配给更新监视程序后,在成功回调中调用
$scope.$apply()
。 不要在angular controller中使用jQueryAjax,这是一种不好的做法。请使用$http服务和承诺。查看$http服务的文档


你能发布一个plnkr吗请用你的HTML页面来更新你的问题,而不是那一行。plnkr不是数据绑定的,但至少你可以看到一些HTML和控制器js部分,它们在你注入的
ng app
ng controller
指令中很重要?我没有在您发布的HTML页面中找到它们。$scope.$apply()正在更改每一条记录并交替编号,并且处于一个永无止境的循环中!:(所以我推测我不能在jquery ajax中使用$scope.apply?它不是json格式的抱歉,这是其他代码留下的错误变量名。json=13,json=10,总是一个数字…我如何调用它,只需将它包装在函数中?1.json没有定义,chrome调试器处于无休止的循环中
$scope.$apply(function(){
    $scope.commentResult = json;
})