angularjs 指令参数 'fn' 不是函数
angularjs directive Argument 'fn' is not a function
我正在使用 angularjs 和打字稿,我正在尝试创建如下指令:
这是我的控制器:
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 ) ;
我正在使用 angularjs 和打字稿,我正在尝试创建如下指令:
这是我的控制器:
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 ) ;