Ionic framework NFC编写示例

Ionic framework NFC编写示例,ionic-framework,nfc,Ionic Framework,Nfc,请注意,我在将$scope数据传递到nfc.write函数时遇到问题,但如果我传入它所写的文字硬代码值,我需要一个示例解决方案,说明如何将用户输入数据写入nfc标记,我所做的一切尝试都没有成功,我所能做的就是从$scope用户数据中添加数据 这就是我所做的一切 HTML 谢谢。在模板中,您的模型是userData(=>$scope.userData)。 在控制器中,您希望将$scope.loginda写入未定义(或可能为NULL)的控制台。因此,日志和payloadData变量都将为空 <

请注意,我在将
$scope
数据传递到
nfc.write
函数时遇到问题,但如果我传入它所写的文字硬代码值,我需要一个示例解决方案,说明如何将用户输入数据写入
nfc标记
,我所做的一切尝试都没有成功,我所能做的就是从
$scope
用户数据中添加数据

这就是我所做的一切

HTML


谢谢。

在模板中,您的模型是userData(=>$scope.userData)。 在控制器中,您希望将$scope.loginda写入未定义(或可能为NULL)的控制台。因此,日志和payloadData变量都将为空

<ion-view view-title="Chats" data-ng-controller="chat as vm">
<ion-content>

    <div class="list">
        <label class="item item-input">
            <span class="input-label">Username</span>
            <input type="text" ng-model="userData.userName">
        </label>

        <label class="item item-input">
            <span class="input-label">Description</span>
            <input type="text" ng-model="userData.description">
        </label>
    </div>

    <fieldset style="clear:both;">
        <input data-ng-click="login()" type="submit" name="submit"
               value="Login" class="more blue" />
    </fieldset>

    {{userData}}
</ion-content>
.controller('chat', function($scope, $cordovaNfc) {

$scope.loginData = {}; // This should get the data from view to be used below

$cordovaNfc.then(function(nfc){

    // I need to find a way to pass in the userData this point
    console.log($scope.loginData); // Here am not getting the data;

    var payloadData = $scope.loginData; // And i did get anything in the payload

    //Use the plugins interface as you go, in a more "angular" way
    nfc.addNdefListener(function(nfcEvent){

        var tnf = ndef.TNF_EXTERNAL_TYPE,   
            recordType = "application/json", 
            payload = payloadData,                
            record,                               
            message = [
               ndef.mimeMediaRecord(recordType, payload)  
            ];            

        nfc.write(
           message,   // write the record itself to the tag
           function (success) { 
               console.log("Wrote data to tag.");
           },
           // this function runs if the write command fails:
           function (reason) {
               alert("There was a problem " + reason);
           }
        );

    }).then(
    //Success callback
    function(nfcEvent){
        console.log("bound success");
    },
    //Fail callback
    function(err){
        console.log("error");
        alert("error");
    });
   });
  })