为什么自定义指令不起作用

时间:2014-07-08 04:18:11

标签: angularjs

我正在尝试实现AngularJS的自定义指令。

让我们说代码如下所示。

<!DOCTYPE html>
<html lang='en' ng-app='testApp'>
    <head>
        <meta charset='utf-8'/>
        <meta http-equiv='X-UA-Compatible' content='IE=edge'/>
        <meta name='viewport' content='width=device-width, initial-scale=1'/>
        <script src="angular.js"></script>
        <script src="searchinput.js"></script>
    </head>
    <body>
        <searchInput></searchInput>
    </body>
</html>

searchInput.js

var testApp = angular.module('testApp', []);
testApp.directive("searchInput", function() {
    return {
          replace:true,
          restrict: 'AE',
          template: '<h3>Hello World!!</h3>'
      }
});

不幸的是,我没有看到预期的结果。有没有人知道我错过了什么?谢谢。

2 个答案:

答案 0 :(得分:6)

变化

<searchInput></searchInput>

<search-input></search-input>

AngularJS documentation 中查看详细信息

答案 1 :(得分:0)

在我的情况下,即使有连字符也无济于事。整个标签必须是小写的(在angularjs / 1.3.16上)。

我的自定义指令@app.route('/posting',methods=['POST']) def posting(): token = request.form['token'] client_namespace = socketio_clients.get(request.remote_addr) if client_namespace: client_namespace.emit('response', {'data': token})) return '1' abort(400) # client does not have a socket connection active 最初无效。然后,我检查了textReplace,这也没有用。最后,使用text-replace进行检查,该工作正常。

相关问题