AngularJS角种子启动项目将指令添加 [英] AngularJS angular-seed starter project adding directives

查看:108
本文介绍了AngularJS角种子启动项目将指令添加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用的角度种子项目( https://github.com/angular/angular -seed )启动一个新项目。我想在一个新的指令添加。

I am trying to use the angular-seed project (https://github.com/angular/angular-seed) to start a new project. I am trying to add in a new directive.

创建testDirective.js文件:

Created testDirective.js file :

'use strict';

angular.module("myApp.testDirective", [])
.directive("testDirective",
        function() {
            return {
                template : "<h1>Made by a directive!</h1>"
            };
        });

包含在index.html的文件,增加了myApp.testDirective到app.js,在view1.js我说:

Included the file in index.html, added "myApp.testDirective" into app.js, in view1.js I added :

'use strict';

angular.module('myApp.view1', ['ngRoute','myApp.testDirective'])

.config(['$routeProvider', function($routeProvider) {
  $routeProvider.when('/view1', {
    templateUrl: 'view1/view1.html',
    controller: 'View1Ctrl'
  });
}])

.controller('View1Ctrl', [function() {

}]);

和view1.html如下:

and view1.html looks like :

<p>This is the partial for view 1.</p>
<div testDirective></div>

然而,当我运行应用程序,什么也不显示,其中testDirective的。不知道在那里我已经错了。

However, when I run the app, nothing shows up where testDirective is. Not sure where I've gone wrong.

推荐答案

当其中一个HTML元素的开始标记中属性的指令,必须将它们转换成短横线。

When including attribute directives inside the opening tag of an HTML element, they must be converted to dashes.

<div test-directive>

这篇关于AngularJS角种子启动项目将指令添加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆