我写了一个Angular js代码,但它没有用

时间:2017-06-21 15:19:18

标签: javascript angularjs

我的controller.js文件:

angular.module("ngcribs").controller("cribsController", function($scope) {
scope.sc = "Hello world!"; });

和我的index.html文件:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title></title>
        <link rel="stylesheet"href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" >
    </head>
    <body ng-app="ngCribs" ng-controller="cribsController">
        <h1>{{ sc }}</h1>
    </body>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/2.5.0/ui-bootstrap.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/2.5.0/ui-bootstrap-tpls.min.js"></script>
    <script src="app.js"></script>
    <script src="scripts/cribsController.js"></script> 

你好世界没有在浏览器中显示请告诉我如何解决它

2 个答案:

答案 0 :(得分:0)

脚本元素需要进入页面的<head><body>,而不是<html>元素。

此外,Angular模块在哪里?在app.js?它肯定存在于某个地方,例如:

angular.module("ngcribs", []);

答案 1 :(得分:0)

更改下面的角度代码和您遗失的&#39; $&#39;在scope.sc

angular.module("ngCribs",[]).controller("cribsController", function($scope) {
$scope.sc = "Hello world!"; 
});

和ng-app应该像&#34; ngCribs&#34;因为C是模块中的大写字

 <body ng-app="ngCribs" ng-controller="cribsController">
        <h1>{{ sc }}</h1>
    </body>