我已经开发了使用intltelinput jquery插件的自定义指令。我想获得包含suc作为国家的丰富价值和所选号码的拨号代码如下;
scope.nationalphoneinfo.number = elem.intlTelInput("getNumber");
scope.nationalphoneinfo.country = elem.intlTelInput("getSelectedCountryData");
scope.nationalphoneinfo.isValid = true;
但我无法在控制器中看到nationalphoneinfo数据。这如何在控制器中获得nationalphoneinfo。
直观的定义:
var intlTepInputDirecitive = pluginDirecitvesModule.directive('intltelinput', function () {
return {
require: "^ngModel",
restrict: "A",
transclude: true,
scope: {
ngModel: "=",
nationalphoneinfo :"=nationalphoneinfo"
},
link: function (scope, elem, attrs, ngModelCtrl) {
elem.intlTelInput({defaultCountry: scope.defaultCountry,
preferredCountries: ["tr", "de", "nl", "us", "fr", "en"],
utilsScript: ASSETS_PATH + "app/bower_components/utils.js"});
elem.bind("blur", function () {
//e.preventDefault();
scope.$apply(function () {
if (elem.intlTelInput("isValidNumber{")) {
scope.nationalphoneinfo.number = elem.intlTelInput("getNumber");
scope.nationalphoneinfo.country = elem.intlTelInput("getSelectedCountryData");
scope.nationalphoneinfo.isValid = true;
} else {
scope.nationalphoneinfo.isValid = false;
}
});
});
}
};
});
html中的指令声明:
<input intltelinput type="tel" id="phone" name="mobilePhone" ng-required="true" class="form-control pl tel" ng-model="mobilePhone" nationalphoneinfo="nationalPhoneInfo">