generator-angular-fullstack指令templateurl不呈现

时间:2015-04-26 20:46:19

标签: angularjs-directive meanjs angular-directive yeoman-generator-angular angular-template

Disclosue:已经彻底检查了重复和主题/偏离主题。这是我的室友在尝试时也遇到的问题所以这显然是一个常见的问题。我发现其他人也遇到了类似的问题,但有些事情已经解决了这个问题。

我对所有这些框架都比较陌生,但我真的可以更多地关注这一点。 我正在使用generator-angular-fullstack,当我只生成一个指令时,templateurl不会像标题所暗示的那样呈现。网络上没有,因为Angular没有这样的工作。我已经尝试编写自己的指令,该指令也没有那么顺利,只能使用模板:而不是templateurl。如果我试试

ng-include="'app/geoData/geoData.html'"

在main.html上它填充得很好,但我发现这是一条糟糕的路线,考虑到html看起来更清晰,我的自定义指令,并且在网络上有另一个呼叫,最终会减慢一切。有什么我想念的吗? generator-angular-fullstack是否有一个尚未更新的新bug?

这是我的指令,它在index.html中调用的main.html上调用。

  'use strict';            
    angular.module('dangerzoneApp')
          .directive('geoData', function () {
                return {
                    templateUrl: 'app/geoData/geoData.html',
                    restrict: 'EA',
                    link: function (scope, element, attrs) {
                    }
                };
          });

这是我的main.html

<div ng-include="'components/navbar/navbar.html'"></div>

<header class="hero-unit" id="banner">
  <div class="container" >
    <h1>O'HAI, there!</h1>       
    <geo-data></geo-data>
    <img src="assets/images/yeoman.png" alt="I'm Yeoman">
  </div>

</header>

<div class="container">
  <div class="row">
    <div class="col-lg-12">  
      <h1 class="page-header">Features:</h1>
      <ul class="nav nav-tabs nav-stacked col-md-4 col-lg-4 col-sm-6" ng-repeat="thing in awesomeThings">
        <li><a href="#" tooltip="{{thing.info}}">{{thing.name}}<button type="button" class="close" ng-click="deleteThing(thing)">&times;</button></a></li>
      </ul>
    </div>
  </div>

  <form class="thing-form">
    <label>Syncs in realtime across clients</label>
    <p class="input-group">
      <input type="text" class="form-control" placeholder="Add a new thing here." ng-model="newThing">
      <span class="input-group-btn">
        <button type="submit" class="btn btn-primary" ng-click="addThing()">Add New</button>
      </span>
    </p>
  </form>
</div>

<footer class="footer">
  <div class="container">
      <p>Angular Fullstack v2.0.13 |
        <a href="https://twitter.com/tyhenkel">@tyhenkel</a> |
         <a href="https://github.com/DaftMonk/generator-angular-fullstack/issues?state=open">Issues</a></p>
  </div>
</footer>

这是我的index.html

<!doctype html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <base href="/">
    <title></title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width">
    <!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
    <!-- build:css(client) app/vendor.css -->
      <!-- bower:css -->
      <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css" />
      <link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.css" />
      <!-- endbower -->
    <!-- endbuild -->
    <!-- build:css({.tmp,client}) app/app.css -->
    <link rel="stylesheet" href="app/app.css">
      <!-- injector:css -->
      <link rel="stylesheet" href="app/account/login/login.css">
      <link rel="stylesheet" href="app/admin/admin.css">
      <link rel="stylesheet" href="app/app.css">
      <link rel="stylesheet" href="app/geoData/geoData.css">
      <link rel="stylesheet" href="app/main/main.css">
      <link rel="stylesheet" href="components/modal/modal.css">
      <!-- endinjector -->
    <!-- endbuild -->
  </head>
  <body ng-app="dangerzoneApp" geo-data>
    <!--[if lt IE 7]>
      <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
    <![endif]-->
<geo-data></geo-data>
    <!-- Add your site or application content here -->
    <div ui-view=""><geo-data></geo-data></div>
<geo-data></geo-data>
    <!-- Google Analytics: change UA-XXXXX-X to be your site's ID -->
    <script>
      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
      })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

      ga('create', 'UA-XXXXX-X');
      ga('send', 'pageview');
    </script>

    <!--[if lt IE 9]>
    <script src="bower_components/es5-shim/es5-shim.js"></script>
    <script src="bower_components/json3/lib/json3.min.js"></script>
    <![endif]-->
    <!-- build:js({client,node_modules}) app/vendor.js -->
      <!-- bower:js -->
      <script src="bower_components/jquery/dist/jquery.js"></script>
      <script src="bower_components/angular/angular.js"></script>
      <script src="bower_components/angular-resource/angular-resource.js"></script>
      <script src="bower_components/angular-cookies/angular-cookies.js"></script>
      <script src="bower_components/angular-sanitize/angular-sanitize.js"></script>
      <script src="bower_components/angular-bootstrap/ui-bootstrap-tpls.js"></script>
      <script src="bower_components/lodash/dist/lodash.compat.js"></script>
      <script src="bower_components/angular-socket-io/socket.js"></script>
      <script src="bower_components/angular-ui-router/release/angular-ui-router.js"></script>
      <!-- endbower -->
      <script src="socket.io-client/socket.io.js"></script>
    <!-- endbuild -->

        <!-- build:js({.tmp,client}) app/app.js -->
        <script src="app/app.js"></script>
          <!-- injector:js -->
          <script src="app/account/account.js"></script>
          <script src="app/account/login/login.controller.js"></script>
          <script src="app/account/settings/settings.controller.js"></script>
          <script src="app/account/signup/signup.controller.js"></script>
          <script src="app/admin/admin.controller.js"></script>
          <script src="app/admin/admin.js"></script>
          <script src="app/main/main.controller.js"></script>
          <script src="app/main/main.js"></script>
          <script src="app/message/message.controller.js"></script>
          <script src="components/auth/auth.service.js"></script>
          <script src="components/auth/user.service.js"></script>
          <script src="components/modal/modal.service.js"></script>
          <script src="components/mongoose-error/mongoose-error.directive.js"></script>
          <script src="components/navbar/navbar.controller.js"></script>
          <script src="components/socket/socket.service.js"></script>
          <!-- endinjector -->
        <!-- endbuild -->
</body>
</html>

文件结构:这是generator-angular-fullstack的标准文件结构。

├── client
│   ├── app                 - All of our app specific components go in here
│   ├── assets              - Custom assets: fonts, images, etc…
│   ├── components          - Our reusable components, non-specific to app

如何在app下设置文件夹。 主

├── main.js                 - Routes
├── main.controller.js      - Controller for our main route
├── main.controller.spec.js - Test
├── main.html               - View
└── main.css               - Styles

如何在app。

下设置geoData文件夹
├── geoData.directive.js      - Controller for our main route
├── geoData.directive.spec.js - Test
├── geoData.html               - View
└── geoData.css               - Styles

我提前为任何拼写错误道歉。我正在寻求帮助而不是聪明的嘴巴。请礼貌和礼貌,因为这是我第一次深入研究这些框架。也提前谢谢!

2 个答案:

答案 0 :(得分:0)

您可以检查index.html文件中是否加载了包含该指令的js文件。这应该可以解决您的问题 - 希望如此。

答案 1 :(得分:0)

知道angular-fullstack的4.0.x目前不支持templateUrl。你必须使用

template: require('filename');

这是最近在angular-fullstack问题2198中诊断出来的,

https://github.com/angular-fullstack/generator-angular-fullstack/issues/2198

这是在你的问题之后被诊断出来的,所以你没有错过找到它。