html和脚本标记没有链接

时间:2016-03-17 05:47:22

标签: javascript jquery html angularjs

我是angularjs的新手并经过Egghead.io个视频..但我无法将js页面链接到html页面。

的index.html

<!DOCTYPE html>
<html>
<head>
    <title>Angular</title>
</head>
<body>
<div ng-app="">
<div ng-controller="FirstCtrl">
    <h4>{{ "data.message"}}</h4>
    <div class="{{data.message}}">  
      Wrap me up in component       
    </div>
</div>  
</div>
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js"></script>
 <script type="text/javascript" src="main.js"></script> 
</body>
</html>

我的 main.js 文件是

function FirstCtrl($scope) {
  $scope.data = {message: "panel"};
}

2 个答案:

答案 0 :(得分:1)

  

您需要将 Baseclass d1 = new Derived1(); Baseclass d2 = new Derived2(); Baseclass b = new Baseclass(); d1.Fun(); d2.Fun(); b.Fun(); 定义为app,将控制器定义为var VARIABLE_NAME=angular.module('APP_NAME')

VARIABLE_NAME.controller('CONTROLLER_NAME', FUNCTION_EXPRESSION)
var myApp = angular.module('myApp', []);
myApp.controller('FirstCtrl', FirstCtrl);

function FirstCtrl($scope) {
  $scope.data = {
    message: "panel"
  };
}

注意:您的<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app="myApp"> <div ng-controller="FirstCtrl"> <h4>{{data.message}}</h4> <div class="{{data.message}}"> Wrap me up in component </div> </div> </div>不应该有引号(""),否则会以字符串形式处理。

答案 1 :(得分:0)

将这些链接移到标记

   <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js">  </script>
  <script type="text/javascript" src="main.js"></script> 

并且您不能将$ scope与模块和控制器一起使用,这必须是

        var app = angular.module('myApp', []);

        app.controller('FirstCtrl', function($scope) {
            $scope.data = {"message": panel};
        });

和html

        <div ng-app="myApp">    

到第一个div 并使用

          {{data.message}}