AngularJS - 在自定义指令中继承 ngModel

AngularJS - Inherit ngModel in custom directive

我有一个这样的自定义指令:

myText.html:

<div>
<label>{{label}}</label>
<input type="text" class="form-control" >
</div>

Javascript:

app.directive("myText", function() {
    return {
        restrict: 'E',
        replace: true,
        templateUrl: "shared/form/myText.html",
        scope : {
            label : "@",
        }
    };
});

我只想包装输入并将标签作为属性处理。

在我看来,我是这样使用指令的:

<my-text label="Name" ng-model="person.firstname"></my-text>

问题是 ng-model 没有将模型绑定到我的输入。

达到这个结果的正确方法是什么? 谢谢

ng-model 放在输入上并将其绑定到隔离范围。

<my-text label=Name model=person.firstname></my-text>

<input type="text" class="form-control" ng-model=model>

return {
    restrict: 'E',
    replace: true,
    templateUrl: "shared/form/myText.html",
    scope : {
        label : "@",
        model: "=",
    }
};