[英]angularjs directive Argument 'fn' is not a function
我在尝试创建如下指令的地方使用angularjs和typescript:
这是我的控制器:
export const test1 = { template: require('./app.html'), controller($scope, $http) { $scope.hello = "hello app"; } };
我知道如何使用javascript创建指令,但是如何使用const然后导入它。
这是我在js中的指令:
export const myDirective = {
directive() {
return {
restrict : "A",
template : "<h1>Made by a directive!</h1>"
};
}
};
我的观点:
<div class="container">
<div class="row">
<div ng-repeat="b in data">
<div my-directive></div>
</div>
</div>
<div>
我正在尝试将其导入并用作:
import angular from 'angular';
import {ngAnimate} from 'angular-animate';
import {ngSanitize} from 'angular-sanitize';
import 'angular-ui-bootstrap';
import 'angular-ui-router';
import routesConfig from './routes';
import {hello} from './app/hello';
import {test1} from './test1/app';
import { myDirective} from './test1/directives'
import './index.scss';
export const app = 'app';
angular
.module(app, ['ngAnimate', 'ngSanitize','ui.router', 'ui.bootstrap'])
.config(routesConfig)
.component('app', hello)
.component('test1', test1)
.directive('myDirective', myDirective ) ;
但是我收到此错误:
Error: [ng:areq] Argument 'fn' is not a function, got Object
您应该注册directive
功能而不是myDirective
对象。
.directive('myDirective', myDirective.directive ) ;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.