我不能使用Unsplash

时间:2016-11-08 06:17:51

标签: javascript node.js

我尝试使用Unsplash获取图片,并希望在我的应用中使用它。 是的我在其中创建了帐户并获得了应用程序ID和其他凭据,我尝试在我的代码中使用https://github.com/unsplash/unsplash-js我先尝试

require('babel-register');
import Unsplash from 'unsplash-js';

const unsplash = new Unsplash({
 applicationId: ApplicationID,
 secret: Secret,
 callbackUrl: callbackUrl
});

首先我写完这段代码后面临问题(错误)

错误

import Unsplash from 'unsplash-js';
^^^^^^

SyntaxError: Unexpected reserved word
  at exports.runInThisContext (vm.js:53:16)
  at Module._compile (module.js:373:25)
  at Object.Module._extensions..js (module.js:416:10)
  at Module.load (module.js:343:32)
  at Function.Module._load (module.js:300:12)
  at Module.require (module.js:353:17)
  at require (internal/module.js:12:17)
  at Object.<anonymous> (E:\Alex\photo\app.js:6:11)
  at Module._compile (module.js:409:26)
  at Object.Module._extensions..js (module.js:416:10)

我收到此错误请给我解决方案。

感谢。

5 个答案:

答案 0 :(得分:2)

您可以使用ng-init

<body data-ng-app="myApp">
 <select  ng-init="recureAdata='Never'" class="form-control" ng-model="recureAdata" id="recure" ng-change="recureidChange()">
    <option ng-value="0">Never</option>
    <option ng-value="1">Every One Week</option>
    <option ng-value="2">Every Two Week</option>
    <option ng-value="3">Every Three Week</option>
    <option ng-value="4">Every Four Week</option>
</select>
</body>

<强> DEMO

答案 1 :(得分:1)

在控制器中,您必须为ng-model="recureAdata"

指定默认选择值
$scope.recureAdata=0

此代码可帮助您将默认值指定为recureAdata

<option ng-value="0">Never</option>

永远不会是您的默认选择值。您可以根据需要更改它。

答案 2 :(得分:1)

  

在您的指令中,您可以设置

     

scope.recureAdata = 0;

     

或在您的控制器中

     

$ scope.recureAdata = 0;

答案 3 :(得分:1)

初始化angular js中的select的最佳选择是使用ng-options。它通过跟踪带有值的选项,提供了初始化选择选项的最佳方法。我已为您附上示例代码。

&#13;
&#13;
<!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
          <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script>
    </head>
    <body ng-app="changeExample" ng-controller="ExampleController">
        <select class="form-control" ng-model="recureAdata" ng-options="Option.Value as Option.Name for Option in Options track by Option.Value" id="recure" ng-change="recureidChange()">
		
	</select>
        <script>
		var app = angular.module("changeExample", []);
		app.controller('ExampleController', ['$scope', function ($scope) {
			$scope.Options = [{
				'Value': 0,
				'Name': 'Never'
			 },
			 {
				'Value': 1,
				'Name': 'Every One Week'
			 },
			 {
				'Value': 2,
				'Name': 'Every Two Week'
			 },
			 {
				'Value': 3,
				'Name': 'Every Three Week'
			 },
			 {
				'Value': 4,
				'Name': 'Every Four Week'
			 }
                        ];
			$scope.recureAdata = $scope.Options[0];
		}]);
		</script>
    </body>
    </html>
&#13;
&#13;
&#13;

答案 4 :(得分:0)

<select class="form-control" ng-model="recureAdata" id="recure" ng-change="recureidChange()">
 <option ng-value="0" ng-selected="true">Never</option>
 <option ng-value="1">Every One Week</option>
 <option ng-value="2">Every Two Week</option>
 <option ng-value="3">Every Three Week</option>
 <option ng-value="4">Every Four Week</option>
</select>