简体   繁体   English

使用angularjs时在哪里包含javascript文件。 我所做的似乎不起作用

[英]Where to include javascript files while using angularjs. What i have done doesn't seem to be working

I want to use javascript in an AngularJS framework but the javascript file is not making any changes to the html code. 我想在AngularJS框架中使用javascript,但是javascript文件未对html代码进行任何更改。

<!DOCTYPE html>
<html lang="en" ng-app>

  <head>
    <meta charset="UTF-8">
    <title>BookArt.com</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
    <link rel="stylesheet" href="app.css">
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.29/angular.min.js"></script>
    <script src="app.js"></script>
  </head>

  <body>

    <div id="header-wrapper" ng-controller="HeaderCtrl">
      <span class="logo pull-left">{{appDetails.title}}</span>
      <span class="tagline pull-left">{{appDetails.tagline}}</span>
      <div class="nav-wrapper pull-left">
        <ul class="nav nav-pills">
          <li class="active"><a href="#">Books</a> </li>
          <li><a href="#">Kart</a> </li>
        </ul>
      </div>
    </div>
  </body>

</html>

Here is my JavaScript file: 这是我的JavaScript文件:

var HeaderCtrl = function($scope) {
  $scope.appDetails = {
    title: "BookArt";tagline: "We have 1 Million books for you.";
  };
}

And here is my CSS file: 这是我的CSS文件:

#header-wrapper{
    width: 100%;
}

.logo{
    padding: 10px;
    margin-right: 10px;
    font-size: 50px;
    font-family: fantasy;
}

.tagline{
    font-size: 13px;
    margin-top: 70px;
    margin-left: -180px;
    font-family: monospace;
}

.nav-wrapper{
    margin-top: 25px;
    margin-left: 100px;
}

Is my javascript file even being loaded? 我的javascript文件是否正在加载? I am also using AngularJS as the framework. 我也使用AngularJS作为框架。 Thanks. 谢谢。

Your object is not valid 您的对象无效

you are using ; 您正在使用; instead of , 而不是,

Try like this 这样尝试

 $scope.appDetails = {
    title: "BookArt",
    tagline: "We have 1 Million books for you."
  };

Working snippet 工作片段

 var HeaderCtrl = function($scope) { $scope.appDetails = { title: "BookArt", tagline: "We have 1 Million books for you.", }; } 
 #header-wrapper { width: 100%; } .logo { padding: 10px; margin-right: 10px; font-size: 50px; font-family: fantasy; } .tagline { font-size: 13px; margin-top: 70px; margin-left: -180px; font-family: monospace; } .nav-wrapper { margin-top: 25px; margin-left: 100px; } 
 <!DOCTYPE html> <html lang="en" ng-app> <head> <meta charset="UTF-8"> <title>BookArt.com</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"> <link rel="stylesheet" href="app.css"> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.29/angular.min.js"></script> <script src="app.js"></script> </head> <body> <div id="header-wrapper" ng-controller="HeaderCtrl"> <span class="logo pull-left">{{appDetails.title}}</span> <span class="tagline pull-left">{{appDetails.tagline}}</span> <div class="nav-wrapper pull-left"> <ul class="nav nav-pills"> <li class="active"><a href="#">Books</a> </li> <li><a href="#">Kart</a> </li> </ul> </div> </div> </body> </html> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SweetAlert2 似乎对我不起作用。 我做错了什么? - SweetAlert2 doesn't seem to work for me . What have i done wrong? 我的 Javascript 似乎不起作用 - DOM 是否已更改? - My Javascript doesn't seem to be working - could the DOM have changed? 为什么javascript没有更好的方法来包含文件? - Why doesn't javascript have a better way to include files? JavaScript碰撞检测似乎不起作用? - JavaScript Collision Detection doesn't seem to be working? &#39;javascript:close()&#39;似乎不起作用 - 'javascript:close()' doesn't seem to be working JavaScript .active 似乎对我不起作用 - JavaScript .active doesn't seem to be working for me OnClick Javascript似乎无法正常运行 - OnClick Javascript doesn't seem to be working properly 在angularjs测试中使用element.triggerHandler()进行粘贴和按键事件似乎没有效果 - Using element.triggerHandler() in angularjs tests for paste and keypress events doesn't seem to have an effect AngularJs。 通过ajax加载的数据未在View中显示 - AngularJs. Data loaded via ajax doesn't shown in View 我想根据用户在文本框中输入的内容来过滤列表。 我正在使用angularJS。 为什么代码不起作用? - I'd like to filter a list according to whatever the user enters in the textbox. I'm using angularJS. Why isn't the code working?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM