Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/394.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 角度JS表达式{{}不工作_Javascript_Angularjs - Fatal编程技术网

Javascript 角度JS表达式{{}不工作

Javascript 角度JS表达式{{}不工作,javascript,angularjs,Javascript,Angularjs,AngularJS表达式不更新视图上的变量值,只是将其打印为源。这是我的控制器代码 controller('loginCtrl', ['$scope', '$state', '$rootScope', function ($scope, $state, $rootScope) { $scope.testMessage = "Test Msg from scope"; $rootScope.testMessageRoot = "Test Msg f

AngularJS表达式不更新视图上的变量值,只是将其打印为源。这是我的控制器代码

controller('loginCtrl', ['$scope', '$state', '$rootScope',
        function ($scope, $state, $rootScope) {

        $scope.testMessage = "Test Msg from scope";
        $rootScope.testMessageRoot = "Test Msg from root scope";
        }]);
当我在视图中使用表达式呈现变量testMessage和testMessageRoot时,它只需按原样打印源代码

<div class="container-fluid" ng-controller="loginCtrl">
    <div class="row">
        <h1>Account Access</h1>
        <h2>{{testMessage}}</h2>
        <h6>{{ 5 + 5 }}</h6>
        <h2>{{$root.testMessageRoot}}</h2>
    </div>
</div>

帐户访问
{{testMessage}}
{{ 5 + 5 }}
{{$root.testMessageRoot}
同一个控制器与ng bind配合良好

<div class="container-fluid" ng-controller="loginCtrl">
<div class="row">
    <h1>Account Access</h1>
    <h2><span ng-bind="testMessage"></span></h2>
    <h6><span ng-bind=" 5 + 5"></span></h6>
    <h2><span ng-bind="$root.testMessageRoot"></span></h2>
</div>

帐户访问


AngularJS v1.3.10在我的应用程序中使用,我无法理解哪里出了问题,感谢您的帮助

是否使用了您在控制器中注入的$state服务


由于“$state”不是有效的角度服务,删除它将解决您的问题。

是的,express的角度表达式存在一些问题,我使用了ng bind而不是表达式,效果很好。

你的结尾在哪里]在第一个示例中,你试图使用
$root.testMessage1
,但在第二个示例中,它是
$root.testMessageRoot
这是一个打字错误吗?@azure1&dmamills:这是一个打字错误,我已经更正了。你确定你包括angular.min.js和jquery.js在您的html中?在JSFIDLE或plunkr中看到代码会很好。嗨,这也不起作用为什么?当我做乘法时,它会工作为什么?