Hello. I have two buttons. I want to send a certain message when a certain button is pressed. I try to send a packet like this
// Ionic Starter App
// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
angular.module('starter', ['ionic'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
chrome.socket.create('udp', '192.168.1.129', 2390, {},
function(socketInfo) {
// The socket is created, now we want to connect to the service
var socketId = socketInfo.socketId;
chrome.socket.connect(socketId, function(result) {
// We are now connected to the socket so send it some data
chrome.socket.write(socketId, arrayBuffer,
function(sendInfo) {
console.log("wrote " + sendInfo.bytesWritten);
}
);
});
}
);
});
})
The button is not connected (I don’t know how to do it); I get this error on the chrome.socket.create line:
Uncaught TypeError: Cannot read property 'create' of undefined
Further attempts:
I tried connecting the buttons like this
html
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
</head>
<body ng-app="starter">
<ion-pane>
<ion-header-bar class="bar-stable">
<h1 class="title">key</h1>
</ion-header-bar>
<ion-content>
<button class="button button-block button-balanced" ng-click="sendcmd('l')">
lock
</button>
<button class="button button-block button-assertive" ng-click="sendcmd('u')">
unlock
</button>
</ion-content>
</ion-pane>
</body>
</html>
js
// Ionic Starter App
// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
angular.module('starter', ['ionic'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
function sendcmd(cmd) {
console.log("cmd: ");
console.log(cmd);
console.log(".\n");
chrome.socket.create('udp', '192.168.1.129', 2390, {},
function(socketInfo) {
// The socket is created, now we want to connect to the service
var socketId = socketInfo.socketId;
chrome.socket.connect(socketId, function(result) {
// We are now connected to the socket so send it some data
chrome.socket.write(socketId, cmd,
function(sendInfo) {
console.log("wrote " + sendInfo.bytesWritten);
}
);
});
}
);
}
```
I don't get any presses logged in the console.
update:
button works like this:
```
angular.module('key', ['ionic'])
.controller('keyctrl', function($scope) {
$scope.sendcmd = function(cmd) {
console.log("cmd: " + cmd);*/
}
});
```