简体   繁体   English

angularjs指令参数'fn'不是函数

[英]angularjs directive Argument 'fn' is not a function

I am using angularjs and typescript where i am trying to create a directive as following: 我在尝试创建如下指令的地方使用angularjs和typescript:

Here is my controller : 这是我的控制器:

 export const test1 = { template: require('./app.html'), controller($scope, $http) { $scope.hello = "hello app"; } }; 

I know how to create a directive using javascript, but how to do it using a const then import it. 我知道如何使用javascript创建指令,但是如何使用const然后导入它。

Here is my directive in js: 这是我在js中的指令:

export const myDirective = {
    directive() {
        return {
        restrict : "A",
        template : "<h1>Made by a directive!</h1>"
    };

    }
};

My View: 我的观点:

<div class="container">
<div class="row">
    <div ng-repeat="b in data">
       <div my-directive></div>

    </div>
</div>
<div>

I am trying to import it and use as: 我正在尝试将其导入并用作:

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 ) ;

However i am getting this error: 但是我收到此错误:

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.

相关问题 AngularJS参数&#39;fn&#39;不是函数,未定义 - AngularJS Argument 'fn' is not a function, got undefined 带参数的angularjs指令绑定函数 - angularjs directive binding function with argument (AngularJS)ng:areq错误参数:参数&#39;fn&#39;不是一个函数,得到对象了吗? - (AngularJS) ng:areq Bad Argument: Argument 'fn' is not a function, got Object? AngularJs:错误:[ng:areq]参数&#39;fn&#39;不是一个函数,未定义 - AngularJs: Error: [ng:areq] Argument 'fn' is not a function, got undefined AngularJS-错误:[ng:areq]参数&#39;fn&#39;不是一个函数,得到了字符串 - AngularJS - Error: [ng:areq] Argument 'fn' is not a function, got string 参数&#39;fn&#39;不是一个函数,得到了对象angularjs [ng:areq] - Argument 'fn' is not a function, got Object angularjs [ng:areq] 在AngularJS中定义初始应用程序-参数&#39;fn&#39;不是一个函数,得到了字符串 - Defining The Initial App in AngularJS - Argument 'fn' is not a function, got string angularjs [ng:areq]参数&#39;fn&#39;不是函数,控制台出现字符串错误 - angularjs [ng:areq] Argument 'fn' is not a function, got string in console error AngularJS 延迟错误:参数“fn”不是函数,得到了对象 - AngularJS defer error: Argument 'fn' is not a function, got Object AngularJS指令 - 将函数作为参数传递给“&”属性 - AngularJS directive - passing function as argument to “&” attribute
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM