簡體   English   中英

angularjs指令參數'fn'不是函數

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM