1

拼命尝试将一个简单的字符串传递给 AngularJS 组件,我有以下 angularJS 组件:

async-typeahead.componenet.js:

angular.module('asyncTypeahead').component('asyncTypeahead', {
    
    templateUrl: 'static/partials/async-typeahead/async-typeahead.template.html',
    bindings: {
        pk: '=',
        object: '=',
        objectType: '@'
    },
    controller: ['$scope','$http',
        function AsyncTypeaheadController($scope, $http) {

             var self = this;


            self.getTags = function (val) {
                console.log("async-typeahead input is: " +val);
                console.log("async-typeahead object keys are: " + angular.toJson(self.object));
                
                console.log("async-typeahead type is: " + angular.toJson(self.objectType));...

并按照 html 调用组件:

<async-typeahead object="$ctrl.actor.actor_tags" objectType={{ This is just a string }}></async-typeahead>

'val' 只是来自预输入的输入。

我已经尝试过objectType={{ This is just a string }}objectType="This is just a string"并且objectType=This is just a string我还尝试将绑定从 '=' 更改为 '@' 或 '>' 结果是一样的:

每当我查看控制台时,我总是会得到:

异步预输入输入为:df

异步预输入对象 kes 是:[37,43,49]

async-typeahead 类型为:未定义

我究竟做错了什么?如何将简单的字符串传递给 angularJS 组件?

4

1 回答 1

2

您在 html 中使用的 objectType 属性存在问题。指令/组件名称及其所有属性应使用“-”分隔。

正确的代码附在下面:

<async-typeahead object="$ctrl.actor.actor_tags" object-type="This is just a string"></async-typeahead>
于 2016-07-16T17:23:30.210 回答