Angularjs 将简单的字符串传递给组件

Angularjs pass simple string to component

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

异步-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 我也试过将绑定从 '=' 更改为 '@' 或 '>' 结果是一样的:

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

async-typeahead input is: df

async-typeahead object kes are: [37,43,49]

async-typeahead type is: undefined

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

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

正确的代码附在下面:

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