Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/419.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.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 angularjs错误,绑定不';不能使用这个关键字_Javascript_Angularjs - Fatal编程技术网

Javascript angularjs错误,绑定不';不能使用这个关键字

Javascript angularjs错误,绑定不';不能使用这个关键字,javascript,angularjs,Javascript,Angularjs,无法开始使用angularjs,需要帮助 我的app.js var app = angular.module('cartApp', ['ui.router']); app.controller('dashboardCtrl', function() { var dash = this; dash.something = "something"; }); index.html <!DOCTYPE html> <html lang="en" ng-app="

无法开始使用angularjs,需要帮助

我的app.js

var app = angular.module('cartApp', ['ui.router']);

app.controller('dashboardCtrl', function() {

    var dash = this;
    dash.something = "something";

});
index.html

<!DOCTYPE html>
<html lang="en" ng-app="cartApp">
<head>
    <meta charset="UTF-8">
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>


    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.3.1/angular-ui-router.js"></script>


</head>
<body ng-controller="dashboardCtrl">{{something}}

/body>
</html>

{{something}}
/正文>

我想我搞砸了,但不知道它在哪里。

您的所有绑定都可以在控制器上下文中使用(
this
),因此您应该使用
controllerAs
模式在视图中的
this
中获得绑定。您将在
ng controller
指令中使用controller
alias
&您应该使用
dash
获得控制器绑定

<body ng-controller="dashboardCtrl as dash">
   {{dash.something}}
</body>

{{dash.something}}
还要确保您已经在页面上引用了
app.js


你能试试控制器吗

 app.controller('dashboardCtrl', function($scope) {

    $scope.something = "something";

});

为了将来的参考,我建议遵循这一点


这是非常有用的,因为它提供了更好的可读性,并且避免了此类错误。

嗨,你能发布完整的错误吗?通常,对于注入错误,它会告诉你哪个模块在注入时有问题。你应该纠正你的
脚本
标记,从
@GeorgeLee开始,哦,它没有错误,只是
{{something}
没有打印。@PankajParkar那只是一个打字错误